From patchwork Wed Sep 23 15:36:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 11795169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D3F6112E for ; Wed, 23 Sep 2020 15:58:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B5D77235F7 for ; Wed, 23 Sep 2020 15:58:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="Bh2Ff6tI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5D77235F7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A77B06B006C; Wed, 23 Sep 2020 11:58:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A01BE6B006E; Wed, 23 Sep 2020 11:58:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C8266B0070; Wed, 23 Sep 2020 11:58:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0019.hostedemail.com [216.40.44.19]) by kanga.kvack.org (Postfix) with ESMTP id 704916B006C for ; Wed, 23 Sep 2020 11:58:22 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 246248443953 for ; Wed, 23 Sep 2020 15:58:22 +0000 (UTC) X-FDA: 77294783244.28.mind27_0406dea27157 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 46288FB7D for ; Wed, 23 Sep 2020 15:36:58 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,prvs=5281df109=sjpark@amazon.com,,RULES_HIT:30029:30046:30051:30054:30064,0,RBL:52.95.48.154:@amazon.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04yr64ahjeg69xm76141gp1w6p1dmypkrtpdynjydkwrg98uoncg11afdxcbucs.dotrcft9c5646b5t46ks4cp33ni516ke6cxexcybfxqekyos1so7eyqnn7ueuf8.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: mind27_0406dea27157 X-Filterd-Recvd-Size: 5206 Received: from smtp-fw-6001.amazon.com (smtp-fw-6001.amazon.com [52.95.48.154]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Sep 2020 15:36:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1600875417; x=1632411417; h=from:to:cc:subject:date:message-id:mime-version; bh=d7cW78cRcUoe0lcVnraOQZxIvx7qYL7x5nzIJpwTCig=; b=Bh2Ff6tId49ALIZqR4vvwhnMwUL4DSxAZcJnm5pZ0VIB6e6HsxkvwRWc Zm9+HzK2JDmFnBXRDtU2KP2EUFdQv3CIisZySe7Z2IPf4cN52yLhFXvuN 1DiaPvy1cN9qF11Y+zoYSbbboknswTjr9Cfr29uWwB7F/wXW1GS5B0SS5 s=; X-IronPort-AV: E=Sophos;i="5.77,293,1596499200"; d="scan'208";a="57257477" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-5bdc5131.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 23 Sep 2020 15:36:54 +0000 Received: from EX13D31EUA004.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2b-5bdc5131.us-west-2.amazon.com (Postfix) with ESMTPS id 2682BA1C8A; Wed, 23 Sep 2020 15:36:53 +0000 (UTC) Received: from u3f2cd687b01c55.ant.amazon.com (10.43.161.237) by EX13D31EUA004.ant.amazon.com (10.43.165.161) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Sep 2020 15:36:48 +0000 From: SeongJae Park To: CC: SeongJae Park , , , , Subject: [RFC PATCH] mm/page_idle: Avoid interferences from concurrent users Date: Wed, 23 Sep 2020 17:36:33 +0200 Message-ID: <20200923153633.21258-1-sjpark@amazon.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.43.161.237] X-ClientProxiedBy: EX13D42UWB004.ant.amazon.com (10.43.161.99) To EX13D31EUA004.ant.amazon.com (10.43.165.161) 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: From: SeongJae Park The flexible interface of Idle Page Tracking can allow concurrent users interfere each other. They could implement their own use user space synchronization, but applications developed by different users would not know how to synchronize with other application. To help this situation, this commit introduces a centralized synchronization infrastructure for Idle Page Tracking. In detail, this commit introduces a mutex for Idle Page Tracking, which exposed to user space via a new sysfs file, 'lock'. By writing to and reading from the file, users can acquire/release and read status of the mutex. While reads of the Idle Page Tracking 'bitmap' file can be done regardless of the mutex status, writes to the file fails if the lock is not held. Note that users could still interfere each other if they do not respect the locking rule. Nevertheless, this will help them noticing the rule. Signed-off-by: SeongJae Park --- mm/page_idle.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mm/page_idle.c b/mm/page_idle.c index 144fb4ed961d..0aa45f848570 100644 --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -16,6 +16,8 @@ #define BITMAP_CHUNK_SIZE sizeof(u64) #define BITMAP_CHUNK_BITS (BITMAP_CHUNK_SIZE * BITS_PER_BYTE) +static DEFINE_MUTEX(page_idle_lock); + /* * Idle page tracking only considers user memory pages, for other types of * pages the idle flag is always unset and an attempt to set it is silently @@ -169,6 +171,9 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj, unsigned long pfn, end_pfn; int bit; + if (!mutex_is_locked(&page_idle_lock)) + return -EPERM; + if (pos % BITMAP_CHUNK_SIZE || count % BITMAP_CHUNK_SIZE) return -EINVAL; @@ -197,17 +202,52 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj, return (char *)in - buf; } +static ssize_t page_idle_lock_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + return sprintf(buf, "%d\n", mutex_is_locked(&page_idle_lock)); +} + +static ssize_t page_idle_lock_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + bool do_lock; + int ret; + + ret = kstrtobool(buf, &do_lock); + if (ret < 0) + return ret; + + if (do_lock) { + if (!mutex_trylock(&page_idle_lock)) + return -EBUSY; + } else { + mutex_unlock(&page_idle_lock); + } + + return count; +} + static struct bin_attribute page_idle_bitmap_attr = __BIN_ATTR(bitmap, 0600, page_idle_bitmap_read, page_idle_bitmap_write, 0); +static struct kobj_attribute page_idle_lock_attr = + __ATTR(lock, 0600, page_idle_lock_show, page_idle_lock_store); + static struct bin_attribute *page_idle_bin_attrs[] = { &page_idle_bitmap_attr, NULL, }; +static struct attribute *page_idle_lock_attrs[] = { + &page_idle_lock_attr.attr, + NULL, +}; + static const struct attribute_group page_idle_attr_group = { .bin_attrs = page_idle_bin_attrs, + .attrs = page_idle_lock_attrs, .name = "page_idle", };