From patchwork Wed May 20 05:28:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michel Lespinasse X-Patchwork-Id: 11559315 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 3ABA160D for ; Wed, 20 May 2020 05:29:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 082F9206C3 for ; Wed, 20 May 2020 05:29:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="viUE7Q+6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 082F9206C3 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 E48DB80055; Wed, 20 May 2020 01:29:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DF8BC8002C; Wed, 20 May 2020 01:29:14 -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 CE7A980055; Wed, 20 May 2020 01:29:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id B80C58002C for ; Wed, 20 May 2020 01:29:14 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8221C40F4 for ; Wed, 20 May 2020 05:29:14 +0000 (UTC) X-FDA: 76835969028.05.park91_50a83ed54f34b X-Spam-Summary: 2,0,0,b652fac4758ff4c9,d41d8cd98f00b204,3kcdexgykclguyjiclemmejc.amkjglsv-kkityai.mpe@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:2198:2199: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.160.202:@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:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: park91_50a83ed54f34b X-Filterd-Recvd-Size: 5819 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 May 2020 05:29:14 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id p31so2562231qte.1 for ; Tue, 19 May 2020 22:29:14 -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=oOKvTis22eNP85Mz9uA/OFT+qhsmJnOFthnsf9VGQzY=; b=viUE7Q+662+IkzFyahnIaYCnJOcXUlVMMDblrHEottDjc4iw8rS5qp3VqL4d9yk4Vl iLsXOlQhtl3Ni8WVCgiTZAXlThHQbBvCRAruZTCadGC5QNJOhYhwVNk58yb7zQWAZpQN m8ea7beMEQVkgnGQE8Kw6TLPJN7uFnreHrikVsiGxB1medgieO5mUY71oBVYYFXFEw1R Qa/W2numx5WhO4pGHeSPhIJZA38/obPSutq/xKAvxx2hwi7DQ8F7U8hqjk85lLb++Wae 8kn2/mNtLie+rrR4TFWKimt/EH4874ceN9jQNTeozxR3hAL//stq/IC+ACWdKSdQQzRI wB+Q== 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=oOKvTis22eNP85Mz9uA/OFT+qhsmJnOFthnsf9VGQzY=; b=nD5Vw/iWamEQvM6aCecPy3x6rK/q26wwMwnBvxJ8w4k+EWaba9GqrzHNkGKg4x99zy z50glc0HyQZVA2qghlBI4J9Gr/q7FVZDpI9ndqUDMSmIQtKRovVjuD+DzpdPwhXJNg+C nxNfgWdz7HshW+Ttlbn9QoxJeEIpGWh9bdktBSsrgE0+gomGMYQS+FtogcVXrIPfE/tw porA0xnZgpUlN3eqHAw/kY6BkFqZCZdZychkh+SGJgPEDhPSzyNdJeUkZtqkP0IvXA7P thuB1jZ1nnAaStgKvRtzXphhMceblPgcvH3NFyWMxno4/RzZ9I7OeZrfpdMSu818uyLS TyWQ== X-Gm-Message-State: AOAM532JJAHMT0Q/iQ7FKg9OtN0myPh+PXNcsoR4RlgTZ0b16si5gz43 ijtY0XaPT9qbj5Ak3YMZpckHElfpzmE= X-Google-Smtp-Source: ABdhPJxHdmAtEVnKOxk3BiJr7dFV6qDRiCtdOzttrQ1X4xOxgL+hGpFSTwe8fs+Y0mMKYecBu0kd59Z48Fg= X-Received: by 2002:a05:6214:1248:: with SMTP id q8mr3157078qvv.130.1589952553394; Tue, 19 May 2020 22:29:13 -0700 (PDT) Date: Tue, 19 May 2020 22:28:57 -0700 In-Reply-To: <20200520052908.204642-1-walken@google.com> Message-Id: <20200520052908.204642-2-walken@google.com> Mime-Version: 1.0 References: <20200520052908.204642-1-walken@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH v6 01/12] 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 , John Hubbard , Michel Lespinasse , Davidlohr Bueso 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 Reviewed-by: Laurent Dufour Reviewed-by: Vlastimil Babka --- 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..97ac53b66052 --- /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_write_downgrade(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 */