From patchwork Mon Jun 13 19:44:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Topi Miettinen X-Patchwork-Id: 9174225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F1686044F for ; Mon, 13 Jun 2016 19:50:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CE642040D for ; Mon, 13 Jun 2016 19:50:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2694262AE; Mon, 13 Jun 2016 19:50:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A848F2040D for ; Mon, 13 Jun 2016 19:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423649AbcFMTqP (ORCPT ); Mon, 13 Jun 2016 15:46:15 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33132 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423235AbcFMTqL (ORCPT ); Mon, 13 Jun 2016 15:46:11 -0400 Received: by mail-wm0-f67.google.com with SMTP id r5so17306956wmr.0; Mon, 13 Jun 2016 12:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zh1WA2ITDhP/4dBa5Z8ON4CbL2pa/Poc4ZNVZE54T90=; b=F9V+uQvPBcpGpfkyLLG8TzfkWzo4Id9Katnk7c1vj0z+7EkwvSgu3e0s/gNz8uMdTV 7hR5/85SKvw3hTdlUwUq8H7DUju6qxEfvWEeBW2fJRpqQKQH1+Y7yyQ62KoEFJg+YPxI V1phn3juWUmYI7BRWiyOVWthzPO2cvFpQZptdEkgdCSfbYNrR4yRYn2h6IF32Ws4fBWC NQROm7FzpTGRY3sGR/ftFp9fs3VI7G9OfIfJXAeJio9tRC7T4yF/OC21Q1Z+80unWYqk exW2JUtX3nyNe7WrOwyrqiKJJZv6l1RzRPuZ96aE1fgQ51RN0at61u3Rms2aedSY/N3q jo0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zh1WA2ITDhP/4dBa5Z8ON4CbL2pa/Poc4ZNVZE54T90=; b=WO7QWtRbC3/83YziZm2QB5FHJUs4MCoHgA/YecNt8+yc3MoLmxqDACY706DU5KE95M 7J7mfBUXvd2goy1L7Hrvc7FRPAq+lglD1rnwO1BsGQKdHH+szPctFKCdQTla0L22BWCe gZ8zSUwdB8/Li4dwfnQLWOKaOnA+odNcb9+Y5w5O8j+hNBAaWUa0jYXggj/FpLUd5MsU fZpcu17yCp74IYkCNl9604XcBF4alYYkFocsFNE1EAoj+leDHjaEOJeu3jgAJ8zry0LD crYUGIZRQ2OatE9csWXJNcgUJeYkiUi62LfA56pvlkIy7sPXA7+fhTuE7g9eeHaoGRRh +dfw== X-Gm-Message-State: ALyK8tKhpUSILxLXV/5VQOX1oiaHYy5S/+m/olSQ1eHa2zuzofaoXN10Hft/i7SN+yQq1Q== X-Received: by 10.28.29.146 with SMTP id d140mr2834826wmd.27.1465847169831; Mon, 13 Jun 2016 12:46:09 -0700 (PDT) Received: from localhost.localdomain ([2001:2003:f54a:b700:2ab2:bdff:fe10:799e]) by smtp.gmail.com with ESMTPSA id c9sm29135737wjh.49.2016.06.13.12.46.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jun 2016 12:46:09 -0700 (PDT) From: Topi Miettinen To: linux-kernel@vger.kernel.org Cc: Topi Miettinen , Alexander Viro , Ingo Molnar , Peter Zijlstra , Andrew Morton , Kees Cook , Cyrill Gorcunov , Alexey Dobriyan , John Stultz , Janis Danisevskis , Calvin Owens , Jann Horn , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)) Subject: [RFC 05/18] limits: track and present RLIMIT_NOFILE actual max Date: Mon, 13 Jun 2016 22:44:12 +0300 Message-Id: <1465847065-3577-6-git-send-email-toiwoton@gmail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465847065-3577-1-git-send-email-toiwoton@gmail.com> References: <1465847065-3577-1-git-send-email-toiwoton@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Track maximum number of files for the process, present current maximum in /proc/self/limits. Signed-off-by: Topi Miettinen --- fs/file.c | 4 ++++ fs/proc/base.c | 10 ++++++---- include/linux/sched.h | 7 +++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/file.c b/fs/file.c index 6b1acdf..2d0d206 100644 --- a/fs/file.c +++ b/fs/file.c @@ -547,6 +547,8 @@ repeat: } #endif + bump_rlimit(RLIMIT_NOFILE, fd); + out: spin_unlock(&files->file_lock); return error; @@ -857,6 +859,8 @@ __releases(&files->file_lock) if (tofree) filp_close(tofree, files); + bump_rlimit(RLIMIT_NOFILE, fd); + return fd; Ebusy: diff --git a/fs/proc/base.c b/fs/proc/base.c index a11eb71..227997b 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -630,8 +630,8 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns, /* * print the file header */ - seq_printf(m, "%-25s %-20s %-20s %-10s\n", - "Limit", "Soft Limit", "Hard Limit", "Units"); + seq_printf(m, "%-25s %-20s %-20s %-10s %-20s\n", + "Limit", "Soft Limit", "Hard Limit", "Units", "Max"); for (i = 0; i < RLIM_NLIMITS; i++) { if (rlim[i].rlim_cur == RLIM_INFINITY) @@ -647,9 +647,11 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns, seq_printf(m, "%-20lu ", rlim[i].rlim_max); if (lnames[i].unit) - seq_printf(m, "%-10s\n", lnames[i].unit); + seq_printf(m, "%-10s", lnames[i].unit); else - seq_putc(m, '\n'); + seq_printf(m, "%-10s", ""); + seq_printf(m, "%-20lu\n", + task->signal->rlim_curmax[i]); } return 0; diff --git a/include/linux/sched.h b/include/linux/sched.h index 9c48a08..0150380 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -782,6 +782,7 @@ struct signal_struct { * have no need to disable irqs. */ struct rlimit rlim[RLIM_NLIMITS]; + unsigned long rlim_curmax[RLIM_NLIMITS]; #ifdef CONFIG_BSD_PROCESS_ACCT struct pacct_struct pacct; /* per-process accounting information */ @@ -3376,6 +3377,12 @@ static inline unsigned long rlimit_max(unsigned int limit) return task_rlimit_max(current, limit); } +static inline void bump_rlimit(unsigned int limit, unsigned long r) +{ + if (READ_ONCE(current->signal->rlim_curmax[limit]) < r) + current->signal->rlim_curmax[limit] = r; +} + #ifdef CONFIG_CPU_FREQ struct update_util_data { void (*func)(struct update_util_data *data,