From patchwork Sat Jan 11 00:28:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Roy X-Patchwork-Id: 11328623 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 D608E138C for ; Sat, 11 Jan 2020 00:29:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A26A02082E for ; Sat, 11 Jan 2020 00:29:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gk7kGspB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A26A02082E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B04D38E0006; Fri, 10 Jan 2020 19:29:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A8D898E0001; Fri, 10 Jan 2020 19:29:12 -0500 (EST) 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 97D028E0006; Fri, 10 Jan 2020 19:29:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 7F37F8E0001 for ; Fri, 10 Jan 2020 19:29:12 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 33F458248041 for ; Sat, 11 Jan 2020 00:29:12 +0000 (UTC) X-FDA: 76363468944.29.drain10_5048fbd5e831e X-Spam-Summary: 2,0,0,83096be27134a47b,d41d8cd98f00b204,arjunroy.kdev@gmail.com,:davem@davemloft.net:netdev@vger.kernel.org:akpm@linux-foundation.org::arjunroy@google.com:arjunroy.kdev@gmail.com:edumazet@google.com:soheil@google.com,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1431:1437:1515:1535:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3871:4321:5007:6119:6261:6653:7514:8957:9413:9592:10004:11026:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12679:12683:12895:12986:13161:13229:13255:13894:14096:14181:14394:14687:14721:21080:21444:21451:21627:21666:21795:21990:30051:30054,0,RBL:209.85.210.194:@gmail.com:.lbl8.mailshell.net-62.50.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:24,LUA_SUMMARY:none X-HE-Tag: drain10_5048fbd5e831e X-Filterd-Recvd-Size: 5410 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Sat, 11 Jan 2020 00:29:11 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id x6so1906073pfo.10 for ; Fri, 10 Jan 2020 16:29:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Z1oljhl2ycEHZWbLZ+RzzjjF8KtGlR4IWad6y7qdb94=; b=gk7kGspB2snM/wkshYVIwZq62scQn7AiKzZqmvDmE1eeD9zllq+nCsUnqYZrxYgXw0 rcSwqB0u7BZjt+oW0LeFqWCb8bZ1P7y2M2RR7zH4hRm2v9KnNZkL9G9ghJ5koK9wIYHF lWEkV3AFMrjLVWJ4rOYZBwAMZDI9rcsi8GwOYN3cw+CTjrN5MQntIrhKTYFKOz+4iyTg eXpk3HeNyZsorkEaykObyFQD2UgT7ETnr7gi3yI/K3MLTn6684Mg1av9TEglTLz9v8Na uRM7f/nctTSBp05yhpJ0rRcwZ9uibtojWeIio/RuGFQ9aSfViKebG8yJR0uCMEd8sT0f eNhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Z1oljhl2ycEHZWbLZ+RzzjjF8KtGlR4IWad6y7qdb94=; b=pboGQN9nmANA5vaV/idaiqKE8yuWKLMtSWW8GnASM+cLRbXE2UMSR+lnRlL22/X15Q JwRu5/VeUQj18dgeq63b/D/ISBtvxFttQhskqxaITunzl3RExhgQwFkiqgMElzaTCtkT 2V7ulxDO5HwBzhLCXBIxNOF7lW/kONZ4Mr2sumQ8hfPJV+UK6hpo7vB1t+MkL37f0ZYb OWa0xTUEi1cvcgtQHODhtC9h9BYcysUvYqBxZdVfI5llGobucK8iiTuU25TY2iz901oN /39G8GDzy4J1NyjNkwItCdnkiU6exfNhe0pfi7B4u/sHkPId/rr3r5EKI9YQNovnTs2S HEng== X-Gm-Message-State: APjAAAVDfpXRc/xtAy5Efch7xfoz0pmx6i0rZdsVFCcPfcfYmm0lehBt xeuJH/Z2Szb09+2bV7lS/VU= X-Google-Smtp-Source: APXvYqxlDo/HhhLT6RpUNEhLbMmrYm1u2/xqNvHPplpw3e/JAZOWpZA1TSDoKgYjE197YNwwCTRNpQ== X-Received: by 2002:a62:62c4:: with SMTP id w187mr7300329pfb.216.1578702550723; Fri, 10 Jan 2020 16:29:10 -0800 (PST) Received: from phantasmagoria.svl.corp.google.com ([2620:15c:2c4:201:2b0a:8c1:6a84:1aa0]) by smtp.gmail.com with ESMTPSA id h126sm4567066pfe.19.2020.01.10.16.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2020 16:29:10 -0800 (PST) From: Arjun Roy To: davem@davemloft.net, netdev@vger.kernel.org, akpm@linux-foundation.org, linux-mm@kvack.org Cc: arjunroy@google.com, Arjun Roy , Eric Dumazet , Soheil Hassas Yeganeh Subject: [PATCH mm,net-next 1/3] mm: Refactor insert_page to prepare for batched-lock insert. Date: Fri, 10 Jan 2020 16:28:47 -0800 Message-Id: <20200111002849.252704-1-arjunroy.kdev@gmail.com> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog MIME-Version: 1.0 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: Add helper methods for vm_insert_page()/insert_page() to prepare for vm_insert_pages(), which batch-inserts pages to reduce spinlock operations when inserting multiple consecutive pages into the user page table. The intention of this patch-set is to reduce atomic ops for tcp zerocopy receives, which normally hits the same spinlock multiple times consecutively. Signed-off-by: Arjun Roy Signed-off-by: Eric Dumazet Signed-off-by: Soheil Hassas Yeganeh --- mm/memory.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 7c6e19bdc428..7e23a9275386 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1693,6 +1693,27 @@ pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr, return pte_alloc_map_lock(mm, pmd, addr, ptl); } +static int validate_page_before_insert(struct page *page) +{ + if (PageAnon(page) || PageSlab(page)) + return -EINVAL; + flush_dcache_page(page); + return 0; +} + +static int insert_page_into_pte_locked(struct mm_struct *mm, pte_t *pte, + unsigned long addr, struct page *page, pgprot_t prot) +{ + if (!pte_none(*pte)) + return -EBUSY; + /* Ok, finally just insert the thing.. */ + get_page(page); + inc_mm_counter_fast(mm, mm_counter_file(page)); + page_add_file_rmap(page, false); + set_pte_at(mm, addr, pte, mk_pte(page, prot)); + return 0; +} + /* * This is the old fallback for page remapping. * @@ -1708,28 +1729,14 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, pte_t *pte; spinlock_t *ptl; - retval = -EINVAL; - if (PageAnon(page) || PageSlab(page)) + retval = validate_page_before_insert(page); + if (retval) goto out; retval = -ENOMEM; - flush_dcache_page(page); pte = get_locked_pte(mm, addr, &ptl); if (!pte) goto out; - retval = -EBUSY; - if (!pte_none(*pte)) - goto out_unlock; - - /* Ok, finally just insert the thing.. */ - get_page(page); - inc_mm_counter_fast(mm, mm_counter_file(page)); - page_add_file_rmap(page, false); - set_pte_at(mm, addr, pte, mk_pte(page, prot)); - - retval = 0; - pte_unmap_unlock(pte, ptl); - return retval; -out_unlock: + retval = insert_page_into_pte_locked(mm, pte, addr, page, prot); pte_unmap_unlock(pte, ptl); out: return retval;