Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262518AbVAPOdM (ORCPT ); Sun, 16 Jan 2005 09:33:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262519AbVAPOdM (ORCPT ); Sun, 16 Jan 2005 09:33:12 -0500 Received: from l247150.ppp.asahi-net.or.jp ([218.219.247.150]:32659 "EHLO mitou.ysato.dip.jp") by vger.kernel.org with ESMTP id S262518AbVAPObC (ORCPT ); Sun, 16 Jan 2005 09:31:02 -0500 Date: Sun, 16 Jan 2005 23:30:58 +0900 Message-ID: From: Yoshinori Sato To: Andrew Morton Cc: linux-kernel@vger.kernel.org Subject: [PATCH] H8/300 mm update User-Agent: Wanderlust/2.11.30 (Wonderwall) SEMI/1.14.6 (Maruoka) LIMIT/1.14.9 (Domyoji) APEL/10.6 Emacs/21.3 (i386-pc-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3780 Lines: 148 o include/asm-h8300/mmu.h: Changeset 1.2053 support o mm/nommu.c: add __vm_enough_memory Signed-off-by: Yoshinori Sato diff -Nru a/include/asm-h8300/mmu.h b/include/asm-h8300/mmu.h --- a/include/asm-h8300/mmu.h 2005-01-16 06:03:02 -08:00 +++ b/include/asm-h8300/mmu.h 2005-01-16 06:03:02 -08:00 @@ -3,19 +3,8 @@ /* Copyright (C) 2002, David McCullough */ -struct mm_rblock_struct { - int size; - int refcount; - void *kblock; -}; - -struct mm_tblock_struct { - struct mm_rblock_struct *rblock; - struct mm_tblock_struct *next; -}; - typedef struct { - struct mm_tblock_struct tblock; + struct vm_list_struct *vmlist; unsigned long end_brk; } mm_context_t; diff -Nru a/mm/nommu.c b/mm/nommu.c --- a/mm/nommu.c 2005-01-16 06:03:02 -08:00 +++ b/mm/nommu.c 2005-01-16 06:03:02 -08:00 @@ -41,8 +41,12 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT; int heap_stack_gap = 0; -EXPORT_SYMBOL(sysctl_max_map_count); EXPORT_SYMBOL(mem_map); +EXPORT_SYMBOL(sysctl_max_map_count); +EXPORT_SYMBOL(sysctl_overcommit_memory); +EXPORT_SYMBOL(sysctl_overcommit_ratio); +EXPORT_SYMBOL(vm_committed_space); +EXPORT_SYMBOL(__vm_enough_memory); /* list of shareable VMAs */ struct rb_root nommu_vma_tree = RB_ROOT; @@ -968,3 +972,90 @@ int even_cows) { } + +/* + * Check that a process has enough memory to allocate a new virtual + * mapping. 0 means there is enough memory for the allocation to + * succeed and -ENOMEM implies there is not. + * + * We currently support three overcommit policies, which are set via the + * vm.overcommit_memory sysctl. See Documentation/vm/overcommit-accounting + * + * Strict overcommit modes added 2002 Feb 26 by Alan Cox. + * Additional code 2002 Jul 20 by Robert Love. + * + * cap_sys_admin is 1 if the process has admin privileges, 0 otherwise. + * + * Note this is a helper function intended to be used by LSMs which + * wish to use this logic. + */ +int __vm_enough_memory(long pages, int cap_sys_admin) +{ + unsigned long free, allowed; + + vm_acct_memory(pages); + + /* + * Sometimes we want to use more memory than we have + */ + if (sysctl_overcommit_memory == OVERCOMMIT_ALWAYS) + return 0; + + if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) { + unsigned long n; + + free = get_page_cache_size(); + free += nr_swap_pages; + + /* + * Any slabs which are created with the + * SLAB_RECLAIM_ACCOUNT flag claim to have contents + * which are reclaimable, under pressure. The dentry + * cache and most inode caches should fall into this + */ + free += atomic_read(&slab_reclaim_pages); + + /* + * Leave the last 3% for root + */ + if (!cap_sys_admin) + free -= free / 32; + + if (free > pages) + return 0; + + /* + * nr_free_pages() is very expensive on large systems, + * only call if we're about to fail. + */ + n = nr_free_pages(); + if (!cap_sys_admin) + n -= n / 32; + free += n; + + if (free > pages) + return 0; + vm_unacct_memory(pages); + return -ENOMEM; + } + + allowed = totalram_pages * sysctl_overcommit_ratio / 100; + /* + * Leave the last 3% for root + */ + if (!cap_sys_admin) + allowed -= allowed / 32; + allowed += total_swap_pages; + + /* Don't let a single process grow too big: + leave 3% of the size of this process for other processes */ + allowed -= current->mm->total_vm / 32; + + if (atomic_read(&vm_committed_space) < allowed) + return 0; + + vm_unacct_memory(pages); + + return -ENOMEM; +} + -- Yoshinori Sato - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/