The number of mip map levels on a texture is defined by the range between GL_TEXTURE_BASE_LEVEL (default 0) and GL_TEXTURE_MAX_LEVEL (default 1000). You can set these manually via glTexParameteri or via glTextureStorage. In case of glTextureStorage the min level will be 0 and the max level will be whatever you hand over as a parameter to glTextureStorage - 1.
glGenerateTextureglGenerateMipmap populates the entire range (in this case 1000 textures). Obviously after the generated mipmap texture reaches a certain size (e.g. 2x2, I'm not sure what the standardized minimum size is) all mip map levels after it will use the same texture. I'm not sure if space is actually allocated for those extra textures or if they just refer to the same texture somehow (probably implementation dependent).
If you want to avoid that overhead and make sure, set GL_TEXTURE_MAX_LEVEL to log_2(n) where n is max(texture_resolution_x,texture_resolution_y) since that is the maximum amount of levels required before the textures gets to a size of 1x1 pixels.