From patchwork Fri Mar 27 22:50:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11463245 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 29EE6913 for ; Fri, 27 Mar 2020 22:51:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EAC7820748 for ; Fri, 27 Mar 2020 22:51:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UtfMSsLb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAC7820748 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 B77896B0032; Fri, 27 Mar 2020 18:51:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B51466B0036; Fri, 27 Mar 2020 18:51:08 -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 A66046B0037; Fri, 27 Mar 2020 18:51:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0154.hostedemail.com [216.40.44.154]) by kanga.kvack.org (Postfix) with ESMTP id 905436B0032 for ; Fri, 27 Mar 2020 18:51:08 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5EBD4181AD0A6 for ; Fri, 27 Mar 2020 22:51:08 +0000 (UTC) X-FDA: 76642639416.24.cap49_441da2e1e520f X-Spam-Summary: 2,0,0,875b7287e13db0da,d41d8cd98f00b204,3won-xgykcfujx871a3bb381.zb985ahk-997ixz7.be3@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:30070:30090,0,RBL:209.85.216.74:@flex--walken.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.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:25,LUA_SUMMARY:none X-HE-Tag: cap49_441da2e1e520f X-Filterd-Recvd-Size: 5540 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Mar 2020 22:51:07 +0000 (UTC) Received: by mail-pj1-f74.google.com with SMTP id q10so8719959pja.1 for ; Fri, 27 Mar 2020 15:51:07 -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=iJr2O2VSdEom9sprdjesxwFTcbpm7uxFQvrhb+UJ72I=; b=UtfMSsLbIJWTCdC6gcQujtnuCwJdlNL2TdP7GN/lyZyF/ng1Gj6++wz8IRuYYirWkU lXA0f+DpZpArOueuC0JI/EA50iBr2CbSeWDJCS3EepWgTP3Af1wZS8GDpAlXW/yEYoDo dbhB1R9/8P0Yf7j4MB45xYK1rkOhn6pb8ntXveSr0m5KR4i8Ruq/r2nh+mJvR5MFU5Bs q0Mj03dQtH2Jx8V4Ufqd4hDUDFaFP8pPXukhn4kJVHi8OZVJPRWq41fRNycs1RZghZdY 1PGQwN/PEjZHA1oKUK1upzMDUY67HPf9gwMRApzvDMbf8qm9kwqtGw4YPxH6k1B90IAw m9BQ== 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=iJr2O2VSdEom9sprdjesxwFTcbpm7uxFQvrhb+UJ72I=; b=loE2QYo0w+AECxWBCpJtuxeYmP3PqHFTDqHQ1tkq89JYm1nMQg7/GRvw/kmgFzZJfX TfpRQdBR/HTn5g62AHwVeQUERJGmv4P0TDhI2f951KIg5SGhzlVvOBI5BKOkEYyXI5Zy T1Cgyb3nkFq/caPd2sgzgjT868w1sbO3YPmfCoTTWttOsXngG209Q5kwuI7Sed8oSQI6 +zLIQW53ueMyqpMduxJxuMyaN+OqWmWF7vFFtGEWbD+CgLa8Q1l5iQ5z9LkzULEbq8KE Qt2ErSwRl4ULeDoL4614dYOXO8Sa9REGutvlnRPhZy//gDq1QGpKAQ0uppPS6WUWJ26s OLdQ== X-Gm-Message-State: ANhLgQ1Ws91tNtVouF4Vl/I7oPwz0d0I3cEZJoqjTB0q+RpAQ9Ukz5E3 K9YCHBQzlQBu5lOVaYO+2sP0BXGHbxM= X-Google-Smtp-Source: ADFU+vtfGqYCjoJCoa5/Pqp1L/DbletTVslglgFg5AREr+0yvewn2NwfxuOB0Nr5QmzyV0NLyUpGbguTqE4= X-Received: by 2002:a63:4e22:: with SMTP id c34mr1636202pgb.263.1585349466748; Fri, 27 Mar 2020 15:51:06 -0700 (PDT) Date: Fri, 27 Mar 2020 15:50:53 -0700 In-Reply-To: <20200327225102.25061-1-walken@google.com> Message-Id: <20200327225102.25061-2-walken@google.com> Mime-Version: 1.0 References: <20200327225102.25061-1-walken@google.com> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog Subject: [PATCH v3 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 , Markus Elfring , 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: SeongJae Park --- 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 c54fb96cb1e6..2f13c9198999 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 */