From patchwork Tue Jan 28 02:59:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Roy X-Patchwork-Id: 11353503 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 9783113A4 for ; Tue, 28 Jan 2020 03:00:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 644152467F for ; Tue, 28 Jan 2020 03:00:06 +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="LiOCq7RX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 644152467F 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 75CE66B000A; Mon, 27 Jan 2020 22:00:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 70E9C6B000C; Mon, 27 Jan 2020 22:00:05 -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 623826B000D; Mon, 27 Jan 2020 22:00:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id 4BD186B000A for ; Mon, 27 Jan 2020 22:00:05 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 00106824805A for ; Tue, 28 Jan 2020 03:00:04 +0000 (UTC) X-FDA: 76425538770.23.chin14_3ad801ab70025 X-Spam-Summary: 2,0,0,123d1ac695f7b20d,d41d8cd98f00b204,arjunroy.kdev@gmail.com,:davem@davemloft.net:netdev@vger.kernel.org:akpm@linux-foundation.org::arjunroy@google.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:7576: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.216.67:@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: chin14_3ad801ab70025 X-Filterd-Recvd-Size: 5406 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 28 Jan 2020 03:00:03 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id m7so278159pjs.0 for ; Mon, 27 Jan 2020 19:00:03 -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=Zb3vaMlCnEIaKoKuEPxaWXPkDmU9sA/hlBePDwvbZxg=; b=LiOCq7RXddMvB8gqmSOf6SqFzuigpHoidXnqfx1tmw4gchYK7DyHGRfRRMRmeiQHa5 JKbTG4aY/Gr6SoFpadbwo62q0ywyr/n3o3LOMTlg76mA6a63mFuE5xmU2ZXO7uZumOi5 Ec4mciVce/7oP2Y+cfIVVW1kxwUFSxeUg4pH3SUXeYl4DyzslPuFRAB/+J9lGqn91bSw NDPQpuPhm/U3Co3DSk5D3hf1a8Wi4F2OIjUJYK6oDRB9CHUGrV2oQ4CykjitPHhMQwRI sgCs2Am8qmGS/sulZboX2fGRFlECoQ31PNVW3HfBi/6L1+mSoit81VWMFpIPqY8Sktiu bIaQ== 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=Zb3vaMlCnEIaKoKuEPxaWXPkDmU9sA/hlBePDwvbZxg=; b=H+IejMgG5bDNG9WyPNjZZ861TYcRzlCKDx6PucoH0E/hG/Cokm5LfDV/z8bs6KX+ji a2dbWTjIihGdRsBmgE3RbD9Zffk65QQ6v4MjPjao70Juu8GxYPS42XPgXEr52kOTLSl2 PAWZKrKv3BmzujViXF/DFSCsupCW0Kf+7k/fbjum8NSIxgnge1yCH+rZCQdcy1ACoKhV DS6dojyrjXFqufMJ/Yop/5Fx781z/T2j6KzaBOK4kCxRr8pNi1AdYSHgVD7ur5Vjuuog ZlBZhcjQ4800Yj5lCjuKiEfD6uT8BkDNGPJOX73ivzEiI4z80nl7QgFrNO5qiqBmLvUR EHaQ== X-Gm-Message-State: APjAAAUAlJPYBoZMPgclRHx8FGR+RnFJ9GftHcI24I93qErriTdgZdcT jqYk3gmOkWPcCpD6KCTpW40= X-Google-Smtp-Source: APXvYqxdehSUpRTXWeeWl84SjIcqzzB1FI5QVI5bMLYuYQHCyF2qDcEOjLEyJArRTHCaPCpAvV9H9w== X-Received: by 2002:a17:90a:858a:: with SMTP id m10mr2092329pjn.117.1580180402682; Mon, 27 Jan 2020 19:00:02 -0800 (PST) Received: from phantasmagoria.svl.corp.google.com ([2620:15c:2c4:201:2b0a:8c1:6a84:1aa0]) by smtp.gmail.com with ESMTPSA id p5sm18184677pga.69.2020.01.27.19.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jan 2020 19:00:02 -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, Eric Dumazet , Soheil Hassas Yeganeh Subject: [PATCH resend mm,net-next 1/3] mm: Refactor insert_page to prepare for batched-lock insert. Date: Mon, 27 Jan 2020 18:59:56 -0800 Message-Id: <20200128025958.43490-1-arjunroy.kdev@gmail.com> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-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: From: Arjun Roy 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 Signed-off-by: Arjun Roy Signed-off-by: Eric Dumazet Signed-off-by: Soheil Hassas Yeganeh Signed-off-by: Andrew Morton --- 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;