Received: by 10.213.65.68 with SMTP id h4csp2247265imn; Thu, 29 Mar 2018 22:12:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx48V4RW7z8sm71A/25gFgAPeS2Tzm1+3+OnGvyinSl2jw3VWWzW5YutwmrWJxmydEhjXUVfC X-Received: by 2002:a17:902:820a:: with SMTP id x10-v6mr11417348pln.105.1522386775645; Thu, 29 Mar 2018 22:12:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522386775; cv=none; d=google.com; s=arc-20160816; b=CSM5aSzm4QhNWsgBE8Q8AzsS2gQPlXDEY62k380KaEZEFx4MiQkMMni7ouj4O3MtQh xc/qT589TdBJFgTkP6/ccjPct7sygaGQ4jzIMebH46jXtsRRuduKcot5MadzqfQPrBLL PD9dgtcfMfMtZqGkN/8k2tk2hVsrQSn9UP2BxQhe3hoUUW/ZR1c1KtvNa0+/B3oNqM+h fwAz5wTcGe+E7xZVp4ISVc0fEeYGGksC4lUCCadasJMiPHYRRlazXQc1N+nHu5nPpHZV HoczsLDuQx7HMQ1/hfdWoqIKV+4yMXv7IUyyKz85ApAzrZMracYQRPsx4iCG3rGGyDyJ GH8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :arc-authentication-results; bh=aQfHJk41w/w6Pfntt7Lc8DUzsOvFmKkEyxG9FkloXX4=; b=J6Pq5hyg5ZbKAHg1n8gdwJ3YCyYiEB6mrY8NjvoTw0PdiPVmGil/P1g8KTZc1Wgs8a ezqbJf9fbJBN6EXpc3T6mP/Z5XbhhPvChPyNOKyUM0f2+/Nlb4aUIXfJiUmsm0XtRjOh ZwelvdqqHJtbjkBRiI4HJvvEohB/rPiXW5W0ZqR3fJCcbTy/l2CC1sCRWoNDvEE3MuIj Fu/3SFF228xFyu1GBAjympp7yP1rm1vY06kXOa7x0eDvN4VV/FuJudxNNi1BH/7B1QGb 4IMSv478XmnTaGhi4wh7OmG0CJlelqcYiVj8LHWAnUrzxNROCYnZLIA/zhd1+qU1SIAP nwiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a84si5836095pfl.154.2018.03.29.22.12.39; Thu, 29 Mar 2018 22:12:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751250AbeC3FL2 (ORCPT + 99 others); Fri, 30 Mar 2018 01:11:28 -0400 Received: from mx56.baidu.com ([61.135.168.56]:14235 "EHLO tc-sys-mailedm04.tc.baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750752AbeC3FL1 (ORCPT ); Fri, 30 Mar 2018 01:11:27 -0400 Received: from localhost (cp01-cos-dev01.cp01.baidu.com [10.92.119.46]) by tc-sys-mailedm04.tc.baidu.com (Postfix) with ESMTP id 2469D236C069; Fri, 30 Mar 2018 13:11:14 +0800 (CST) From: Li RongQing To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: limit a process RSS Date: Fri, 30 Mar 2018 13:11:14 +0800 Message-Id: <1522386674-12047-1-git-send-email-lirongqing@baidu.com> X-Mailer: git-send-email 1.7.10.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org we cannot limit a process RSS although there is ulimit -m, not sure why and when ulimit -m is not working, make it work similar requirement: https://stackoverflow.com/questions/3360348/why-ulimit-cant-limit-resident-memory-successfully-and-how Signed-off-by: Li RongQing --- mm/memory.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 5fcfc24904d1..50cf9399477c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4140,6 +4140,9 @@ int handle_mm_fault(struct vm_area_struct *vma, unsigned long address, ret = __handle_mm_fault(vma, address, flags); if (flags & FAULT_FLAG_USER) { + unsigned long total_rss = get_mm_rss(current->mm); + u64 rlimit; + mem_cgroup_oom_disable(); /* * The task may have entered a memcg OOM situation but @@ -4149,6 +4152,17 @@ int handle_mm_fault(struct vm_area_struct *vma, unsigned long address, */ if (task_in_memcg_oom(current) && !(ret & VM_FAULT_OOM)) mem_cgroup_oom_synchronize(false); + + rlimit = current->signal->rlim[RLIMIT_RSS].rlim_cur; + + if (unlikely(total_rss > (rlimit >> PAGE_SHIFT)) && + (current->pid != 1)) { + + pr_info("kill process %s rsslimit[%lluK] rss[%luK]\n", + current->comm, (rlimit >> 10), + total_rss << (PAGE_SHIFT - 10)); + do_group_exit(SIGKILL); + } } return ret; -- 2.11.0