From patchwork Wed Apr 15 00:43:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11489437 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 19D351392 for ; Wed, 15 Apr 2020 00:44:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0CC6206D9 for ; Wed, 15 Apr 2020 00:44:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ppeFKkXH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0CC6206D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 453968E0006; Tue, 14 Apr 2020 20:44:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 402E58E0001; Tue, 14 Apr 2020 20:44:00 -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 319FE8E0006; Tue, 14 Apr 2020 20:44:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id 1AFFB8E0001 for ; Tue, 14 Apr 2020 20:44:00 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D705E180AD807 for ; Wed, 15 Apr 2020 00:43:59 +0000 (UTC) X-FDA: 76708242198.25.girl54_3ff5d7542023f X-Spam-Summary: 2,0,0,cc2fd49aca471815,d41d8cd98f00b204,3zliwxgykcnmlza93c5dd5a3.1dba7cjm-bb9kz19.dg5@flex--walken.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3870:3872:4321:4605:5007:6261:6653:6742:9969:10004:10400:11026:11232:11473:11658:11914:12043:12291:12296:12297:12438:12555:12683:12895:12986:13149:13230:14096:14097:14181:14394:14659:14721:21080:21444:21451:21627:21990:30054:30064:30070:30090,0,RBL:209.85.214.201:@flex--walken.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.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: girl54_3ff5d7542023f X-Filterd-Recvd-Size: 5601 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Apr 2020 00:43:59 +0000 (UTC) Received: by mail-pl1-f201.google.com with SMTP id a8so1407987plm.2 for ; Tue, 14 Apr 2020 17:43:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=l94C8AK+mUgLYQwrQ+fXnOHMPf8DqDjIiWG1XX6H7Ec=; b=ppeFKkXHMm35q46GgKPv9sdZ6Tqxtm1z5m3TTB4oOmL4XBF34pgNgI6POCdpKssT/N v8CbRWth1V61g5Htw4NIsfPEuz2B/zrwMCC0nV3MUriV9RMFMz2ctgkgeaadhIT3cL9W 42UjpsCFHJxtX7awBdUm2MxhirlGajVmngK5A5fEkaKV8l/xjNAbUjXgY7Sw8DZsOyKJ nc1afK8YKYkFVJLXNntGuukspPexoy1FK2YyevBcpjZ+pTS//WjwfA5HEclvXDHM2vxu nSDzpc6Bzic4DDLDekRerWGm53M6OIWmxgn/tHhHztto5f+d8cxcOdKZo5rLfWY4KAQM zBAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=l94C8AK+mUgLYQwrQ+fXnOHMPf8DqDjIiWG1XX6H7Ec=; b=fWAkAdVXkjf3m0QHaqSHa84gZqCBv30ifmczV59ZKnjdNbvPO2EGc2WIj2n+z/ZlYc 5BePw82AycOkc6zSdTiIpMFGMEbHZvujnbhSdleLNXKI8wfhmOCkz0JnsGrvSPrlSdDb qAnpdWxy3EziWAe9psciOYkxw83ImFqDw7UgFpJtU1kR3jWbM3hMrQ6s/gZJFk/hmRiI 0X6Nv7i+Lgf6ZNlF9kMqTwdl5ghCWPORAgzWMjxsHuh2xj9qBoGO2vASrJerzkBgbs7H 5OpRsyItBY0SotR7Q4yBJ23PNOoS9bxBTSMZoNtu3LM+mgtjnjj8nL4uDiRS8nwCeyfQ S5Qw== X-Gm-Message-State: AGi0PuYPfgDF7c+BTWnmiZhYqbcAJ+/vEfmgxwY6ljsExIfY60iKwOHy aOGT9vb1fNwBs3SntRGZXJZg+Rz2Zdo= X-Google-Smtp-Source: APiQypLqLcVmwiH9GYjRHsC6Au6hrD2No9rLdY7vhYQd1JK6hU4NUeWrBiYgMQdiT4ZiLVjhe+Vuo2tOODA= X-Received: by 2002:a17:90a:1a10:: with SMTP id 16mr3269326pjk.31.1586911438402; Tue, 14 Apr 2020 17:43:58 -0700 (PDT) Date: Tue, 14 Apr 2020 17:43:44 -0700 In-Reply-To: <20200415004353.130248-1-walken@google.com> Message-Id: <20200415004353.130248-2-walken@google.com> Mime-Version: 1.0 References: <20200415004353.130248-1-walken@google.com> X-Mailer: git-send-email 2.26.0.110.g2183baf09c-goog Subject: [PATCH v4 01/10] mmap locking API: initial implementation as rwsem wrappers From: Michel Lespinasse To: Andrew Morton , linux-mm Cc: LKML , Peter Zijlstra , Laurent Dufour , Vlastimil Babka , Matthew Wilcox , Liam Howlett , Jerome Glisse , Davidlohr Bueso , David Rientjes , Hugh Dickins , Ying Han , Jason Gunthorpe , Daniel Jordan , Michel Lespinasse 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 change wraps the existing mmap_sem related rwsem calls into a new mmap locking API. There are two justifications for the new API: - At first, it provides an easy hooking point to instrument mmap_sem locking latencies independently of any other rwsems. - In the future, it may be a starting point for replacing the rwsem implementation with a different one, such as range locks. Signed-off-by: Michel Lespinasse Reviewed-by: Daniel Jordan Reviewed-by: Davidlohr Bueso --- include/linux/mm.h | 1 + include/linux/mmap_lock.h | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 include/linux/mmap_lock.h diff --git a/include/linux/mm.h b/include/linux/mm.h index 5a323422d783..051ec782bdbb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/mmap_lock.h b/include/linux/mmap_lock.h new file mode 100644 index 000000000000..8b5a3cd56118 --- /dev/null +++ b/include/linux/mmap_lock.h @@ -0,0 +1,54 @@ +#ifndef _LINUX_MMAP_LOCK_H +#define _LINUX_MMAP_LOCK_H + +static inline void mmap_init_lock(struct mm_struct *mm) +{ + init_rwsem(&mm->mmap_sem); +} + +static inline void mmap_write_lock(struct mm_struct *mm) +{ + down_write(&mm->mmap_sem); +} + +static inline int mmap_write_lock_killable(struct mm_struct *mm) +{ + return down_write_killable(&mm->mmap_sem); +} + +static inline bool mmap_write_trylock(struct mm_struct *mm) +{ + return down_write_trylock(&mm->mmap_sem) != 0; +} + +static inline void mmap_write_unlock(struct mm_struct *mm) +{ + up_write(&mm->mmap_sem); +} + +static inline void mmap_downgrade_write_lock(struct mm_struct *mm) +{ + downgrade_write(&mm->mmap_sem); +} + +static inline void mmap_read_lock(struct mm_struct *mm) +{ + down_read(&mm->mmap_sem); +} + +static inline int mmap_read_lock_killable(struct mm_struct *mm) +{ + return down_read_killable(&mm->mmap_sem); +} + +static inline bool mmap_read_trylock(struct mm_struct *mm) +{ + return down_read_trylock(&mm->mmap_sem) != 0; +} + +static inline void mmap_read_unlock(struct mm_struct *mm) +{ + up_read(&mm->mmap_sem); +} + +#endif /* _LINUX_MMAP_LOCK_H */