Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3067057ybi; Mon, 29 Jul 2019 00:11:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwszgf/f6+MugDjBKchm7nYLFiGBR0ymQKClrqPwA6CC8RpHE5Wh2z9YpNUsx9lXQWDzsP5 X-Received: by 2002:a17:90b:f12:: with SMTP id br18mr105949539pjb.127.1564384311740; Mon, 29 Jul 2019 00:11:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564384311; cv=none; d=google.com; s=arc-20160816; b=XXq6crlNvGNhnLvU7xDHkWqf8H2TgHmuyb2SygXQ1w6sXq38i7xeHqu7Z6Sxor3aG+ I+pi0Jb9mf5QEOj9elzlw03RN9wB5UnGRgUEugMxnUwJlmV0MCOFgijdoLfFGE7RExrC Y2wLvdg4qcgpmilRjkZXpuqiVyRNOjlIM7BteYhmX8mtNzsftSQvfB+EpA7XqpEWDWKd 7dyBbKiDZNrmopPwp6WxpAkq/lYezcNkdW+ROpbobvh0696DRDK2/GHb6/kALZBmKJWB eL+22v5NUF386dcrXuqvE4L2A2snEA5miJDWPJuYFjizMiyyyJWC31Eef2vuH5RXkLA7 AFEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MP9bWqLglik/G7ydzgpH6qxtoOPjTnKjIEZbq35U0w8=; b=A5gFRyW42G+0ahuvbDBdhhE1NXTV+CauvNwBFj1r7XsfZfAIKdkpDx/AkFkkix9Chh 6Nb7X2XyVU2gIuZswmirjUNQG4E0z5VR3wvlCNGatDxK0PU9yyng79D3gFOWgSd+i/TT 3LyQzfX3xDtXpDTUQUEU9D3A/jQ2BNGVMOn0uDJvy2TnuTgic0sWD+EcKKPgETbwjogj zhItI+f4hyxaK3BV3S4+e7rxCQqbiiAch+uvXzZIacPFFp2bof0ONvu3K1HQL/Je70zm 81jHIsApq7J1j0u1L7c8ug4wkxhVh9e1J2wX/G0qfU0Mxlv+mRHIgayieiR4c4GeU2ip FIDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=GbpKZO+1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si24282954plb.345.2019.07.29.00.11.36; Mon, 29 Jul 2019 00:11:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=GbpKZO+1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbfG2HKq (ORCPT + 99 others); Mon, 29 Jul 2019 03:10:46 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35955 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725957AbfG2HKq (ORCPT ); Mon, 29 Jul 2019 03:10:46 -0400 Received: by mail-pg1-f193.google.com with SMTP id l21so27751409pgm.3 for ; Mon, 29 Jul 2019 00:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MP9bWqLglik/G7ydzgpH6qxtoOPjTnKjIEZbq35U0w8=; b=GbpKZO+1qWJF5PiJfpJI+X1d49LQDhRSEjabzM4QoQoxyPC/ykpjviHT067xaP4ur9 Q8obYhARMbKPZN2+MUi7KS43dNzPuKR0TZprepoLgqL8dD+kKWF7yA9cJNsgLDuWAebQ 0gfhz135PdhcmBO/tQ+4kqQB0rCDV9+w4pqCBPOlGYoT71nY1o7yaEyjkMRD7hBR1P5C yhPQ3G7yavjMpqxRD9NSxGBh3X0PbYCwpznGkB3NPHVGfrc0PBFT5fj7o+pFYkL6z117 bVr0nUhG4ri8CNjgE/N7liJe66keFa5uc+KTxXZUTrXVXIUPyjeXYn3corPlUzoq8C+Z tqKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=MP9bWqLglik/G7ydzgpH6qxtoOPjTnKjIEZbq35U0w8=; b=q6PHRk7fWEuAk1+zQKhjja+g5Gk5ytYdQsx6GsVJ0xHloRmcBcnugeJ2Ai0Mcv1jtF h8H44Y1PUev1aDwEXPbGQhQmlrhxJG6gC8F0eyXS70m69UYdYC3wONzKvzrTavwodOq2 DUWRlbob1Bmb8bcgOng4b6uHyuCkdrkV10yIq9CO34shz8LZLZziEdxAWNPJoU0iXWn7 ELXx2MTlMzrGEouFMy7xwwfDmx9DF2vZpQAgvWAJrXlwMOd8wnh+xJaNYcfRP0VCbjOw DpvAGaadfrNAtN2cAGwQ6qzcft7tBDMsYacVnJsd8QGflmiSRPUpHhLN7z+WBUHjBBI/ o3tA== X-Gm-Message-State: APjAAAXQ0cmwts5bQHIVAlJMdSHYZu/JsmdvG5PYs3rdsu+nT0gjRqsp KFqt80T/ZaXXBi/DaUNNyrc= X-Received: by 2002:a63:2784:: with SMTP id n126mr99458545pgn.92.1564384245259; Mon, 29 Jul 2019 00:10:45 -0700 (PDT) Received: from bbox-2.seo.corp.google.com ([2401:fa00:d:0:98f1:8b3d:1f37:3e8]) by smtp.gmail.com with ESMTPSA id i124sm111028139pfe.61.2019.07.29.00.10.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 00:10:44 -0700 (PDT) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , Minchan Kim , Miguel de Dios , Wei Wang , Michal Hocko , Johannes Weiner , Mel Gorman Subject: [PATCH] mm: release the spinlock on zap_pte_range Date: Mon, 29 Jul 2019 16:10:37 +0900 Message-Id: <20190729071037.241581-1-minchan@kernel.org> X-Mailer: git-send-email 2.22.0.709.g102302147b-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In our testing(carmera recording), Miguel and Wei found unmap_page_range takes above 6ms with preemption disabled easily. When I see that, the reason is it holds page table spinlock during entire 512 page operation in a PMD. 6.2ms is never trivial for user experince if RT task couldn't run in the time because it could make frame drop or glitch audio problem. This patch adds preemption point like coyp_pte_range. Reported-by: Miguel de Dios Reported-by: Wei Wang Cc: Michal Hocko Cc: Johannes Weiner Cc: Mel Gorman Signed-off-by: Minchan Kim --- mm/memory.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 2e796372927fd..bc3e0c5e4f89b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1007,6 +1007,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, struct zap_details *details) { struct mm_struct *mm = tlb->mm; + int progress = 0; int force_flush = 0; int rss[NR_MM_COUNTERS]; spinlock_t *ptl; @@ -1022,7 +1023,16 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, flush_tlb_batched_pending(mm); arch_enter_lazy_mmu_mode(); do { - pte_t ptent = *pte; + pte_t ptent; + + if (progress >= 32) { + progress = 0; + if (need_resched()) + break; + } + progress += 8; + + ptent = *pte; if (pte_none(ptent)) continue; @@ -1123,8 +1133,11 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (force_flush) { force_flush = 0; tlb_flush_mmu(tlb); - if (addr != end) - goto again; + } + + if (addr != end) { + progress = 0; + goto again; } return addr; -- 2.22.0.709.g102302147b-goog