From patchwork Fri Jun 24 08:04:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12894084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F31CCA481 for ; Fri, 24 Jun 2022 08:04:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15E4D8E01E7; Fri, 24 Jun 2022 04:04:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06C498E01F3; Fri, 24 Jun 2022 04:04:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDA748E01E7; Fri, 24 Jun 2022 04:04:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B3FC98E01F3 for ; Fri, 24 Jun 2022 04:04:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 888E020F06 for ; Fri, 24 Jun 2022 08:04:53 +0000 (UTC) X-FDA: 79612393266.09.A6F5FC6 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by imf29.hostedemail.com (Postfix) with ESMTP id 20AFA120024 for ; Fri, 24 Jun 2022 08:04:53 +0000 (UTC) Received: by mail-ed1-f41.google.com with SMTP id ej4so2305054edb.7 for ; Fri, 24 Jun 2022 01:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p1KsJJhvBthReekWVkDyI4HkkhGOTDE0uEXhDskma64=; b=KRem//CoENhA5H2UpmZZdJhIsNw+EqHDcRDSpekGpVdLUsKXbAGMuEpz4BJJr9Z87z IFYClc3R1wwPUygzstZ5aUNS6Wq5y0CfGSvfoDrVHkFbu0scIpPzWzMEq6eV8O7oB/AX FqDJRWt2Ipnk6y0r0VVTgjAU7cmOXdZEoJ0Qo2ZbG6rmkxKpX6vKZa5MuOPpSarFPIOI rvJt3BfdWDmWUzFnm2BJraq/RqKiudFoTZr0bvTI3SMqicR6ERRh4vwjGTYV2bCjY/8g Cs+cebdzqLUOjb0//Sl+P40ocJPd2A5kT/PXdXVI6tczXXpaQaD+aGMxYg5hyRLGbgEA pMnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p1KsJJhvBthReekWVkDyI4HkkhGOTDE0uEXhDskma64=; b=Q1nABGuoUsUcALt2e4iWLCAelW6p1vSyKC8r1XGkbyT6/qUSW04/i5UV3eW5o/c+vf 8cm1tTltBK3keLimUE+PmItWHw1RniCBLdrz4bDIMU4HiFVzrd7J+Pf4NiuqEd9AWo9a M6+FOm+/xDHYnxFsMEyYZlju9iVYjAKFlU0HsRWHAes9C3v6J7hoY/MzY0KdI+12lxGF nmvgJ67xnhq2o+GTjI5LSaVPY5+a8qiAiOQlO9SFS/Zidj9s2hDfdi5xABipjx4XNvKr xkJo0xrkNSoaJG7p3P/EdPGAlUK9vpyCtVnQLLMRmYYW/mecboijorhoU1Twlt3NWt5w FF8w== X-Gm-Message-State: AJIora+/5T/sngGBEyyup/86OFH/hJjWUCJwMepdwC4l07xQIUtv92Cx RIpxItjEOjYnDIuJVI7RMYA= X-Google-Smtp-Source: AGRyM1sHNTKfIbC1nDS/xDvZBcuQhpYMoeUWuMsHYIL5xwYmRCaeHIcH9pVKRTHXqSe2jlNLioeTeQ== X-Received: by 2002:a05:6402:3807:b0:435:20fb:318d with SMTP id es7-20020a056402380700b0043520fb318dmr15936277edb.272.1656057892772; Fri, 24 Jun 2022 01:04:52 -0700 (PDT) Received: from able.fritz.box (p57b0bd9f.dip0.t-ipconnect.de. [87.176.189.159]) by smtp.gmail.com with ESMTPSA id c19-20020a170906155300b006fea43db5c1sm697779ejd.21.2022.06.24.01.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jun 2022 01:04:52 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org Cc: mhocko@suse.com, =?utf-8?q?Christian_K=C3=B6nig?= Subject: [PATCH 04/14] mm: shmem: provide RSS for shmem files Date: Fri, 24 Jun 2022 10:04:34 +0200 Message-Id: <20220624080444.7619-5-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220624080444.7619-1-christian.koenig@amd.com> References: <20220624080444.7619-1-christian.koenig@amd.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="KRem//Co"; spf=pass (imf29.hostedemail.com: domain of ckoenig.leichtzumerken@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=ckoenig.leichtzumerken@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656057893; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=p1KsJJhvBthReekWVkDyI4HkkhGOTDE0uEXhDskma64=; b=DmKUFfvztvKi4RjbVNh9KfNw0RWM6YFKoX6A6EIAV3144MvIgfPDKJ4LWjd4SasSyEx7bJ aa//RaEW8YVfaeFpN8H9RDBvFrou+EmJoTNJEU7GslB9jjh2rSHTRBGlbWF3Z2i+g7YXHe OInbJP54uflVMqokz3HlUsISUKYhw1c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656057893; a=rsa-sha256; cv=none; b=xzVE1xhyfrH5oKBxe4UwnBUwWR0hn6TSO+P4PzAVI5zUcgDe8jPuHQimiwVYjxPVpbV1S6 CfwhayfMVSKBJSBFQ4V04HJC6wnPQ6LVd3V5BdJo3EuJg7fDoTchQwD8Z9Q/6UkOArCJIS L8QYQGCN4Vq2sonb3zsrUzXhwyzUMRQ= X-Stat-Signature: mae4y11c1knq5bbi4dbexbb5t939615z X-Rspamd-Queue-Id: 20AFA120024 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="KRem//Co"; spf=pass (imf29.hostedemail.com: domain of ckoenig.leichtzumerken@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=ckoenig.leichtzumerken@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam02 X-HE-Tag: 1656057893-332975 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This gives the OOM killer an additional hint which processes are referencing shmem files with potentially no other accounting for them. Signed-off-by: Christian König --- mm/shmem.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index a6f565308133..b068ac5ba4bf 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2209,6 +2209,21 @@ unsigned long shmem_get_unmapped_area(struct file *file, return inflated_addr; } +static long shmem_file_rss(struct file *file) +{ + struct inode *inode = file_inode(file); + unsigned long nrpages; + + /* Only account shmem files which aren't part of any fs */ + if (atomic_read(&inode->i_count) > 1) + return 0; + + xa_lock(&file->f_mapping->i_pages); + nrpages = file->f_mapping->nrpages; + xa_unlock(&file->f_mapping->i_pages); + return nrpages; +} + #ifdef CONFIG_NUMA static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) { @@ -3811,6 +3826,7 @@ EXPORT_SYMBOL(shmem_aops); static const struct file_operations shmem_file_operations = { .mmap = shmem_mmap, .get_unmapped_area = shmem_get_unmapped_area, + .file_rss = shmem_file_rss, #ifdef CONFIG_TMPFS .llseek = shmem_file_llseek, .read_iter = shmem_file_read_iter,