As an H-1B nonimmigrant, you may be admitted for a period of up to three years. Your time period may be extended, but generally cannot go beyond a total of six years, though some exceptions do apply under sections 104(c) and 106(a) of the American Competitiveness in the Twenty-First Century Act (AC21).
According to AC21, you may extend your H1B status annually in one-year increments if your green card process was started at least 365 days prior to the day when you reach the six-year limit and was still pending. Or, if your I-140 has already been approved but your priority date is not current, i.e. immigrant visa number is not available to you, you may apply for three-year extensions of your H-1B status.
Therefore, if your H1B status has come close to the 6 years limit and you plan to stay in the US beyond the 6 years limit, it is important for you to start your immigrant petition as soon as possible.