Hi Dong,
there are two bits in the patch I think need some decision:
1) In admin/health.php you use:
raise_memory_limit($oldmemlimit);
and that won't work, because that function is only able to raise mem, never lower it. So, perhaps, it will need the original ini_set() or so.
2) About the new configuration setting, I think it's a good idea, but perhaps it would be interesting to have it only with big values: 64MB, 128MB, 256MB, 512MB, 1024MB explaining in what exact parts of Moodle it's going to be used (search indexing, backup & restore, admin/health.php), perhaps also in Moodle Docs page. But in any case, always specifying that any setting in php.ini will have precedence. I'd make it to default to 128MB and apply it to those 3 places: search indexing, backup & restore, admin/health.php for now. Let's see if we need to apply it to more places along the time. And note install.php isn't it the list, 40M is ok there IMO.
Feel free to comment with MD if you want. Ciao 
Assigning to Dongsheng...
IMO all those ini_set('memory_limit', XX) directives should be replaced by the raise_memory_limit(XX) function that handles the same but respecting php.ini settings.
Note that the function is in lib/setuplib.php and I'm not sure if that lib is included always, so must be checked.
Can your review that, plz? TIA! Ciao