Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5030072imm; Tue, 12 Jun 2018 01:06:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIxjf7LXEwdHRfhgf+wiur5qykLi6zbh/bmC+vXtpNwFnG6xkfo0bfA8YykEzWe/uMBEA/q X-Received: by 2002:a17:902:125:: with SMTP id 34-v6mr2944641plb.42.1528790770658; Tue, 12 Jun 2018 01:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528790770; cv=none; d=google.com; s=arc-20160816; b=AzNEJVdkl74jRqJ06NBMP/x8t5ofTsjGcZ3+LX1pxVUiHHlXzE2toi9/xUbuiaMkth qJGOZA5Z2H9HqMggSEeVSaomyWJ6wYT7L9l2MxAxH0LYJII1r3f3BOFEEb9l3cu1upt0 GF/ljKvqggHgl0KDbJaAfnhy9FpdFGpq2MkL1cgVvM6ZF0tO6ngAmOC3yU1GK1aaDPsO QPeEPw6L98tgFhjCynJAgSK/lZ/5cxoO69qdbUgV5hAlEF4gLN7hWjDE5nC3Z6WNfUm8 MYyJxRlXq37awLPT1MkXWWIP1x2crVoTIEWXfjhFr/MAuf+zCCnd4Y19GmbXnWmvTIjU VuMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=e30WJON+WcienBTt3dkXZkI8oWzd8tFR4OMY8R/zNUM=; b=jTzIIlM+e/sod6lRsOoiqbZILVFUfkeIeaglgUtKfwKkUQbrwB/0rvJAY01LSmy7iE GZRd3YDcFhW6exMweuN306Z0Owc5NNV3wqgAwyQFqzFhzFdB8GFPlE4Ock8h69TKcyag Lfe6M48YsPMPASNbQaWE1H+T0d+rK8pGiSHXxZcAuG2Lgke6fnmkLPHOfd+8ast/5azA EB51nQZksx/tAHImGdJNfoOWbAvShUFXYreoela1W0DcrTUs8PKhO+tRV445tJ6m775s QuuOblR2za7JmSEGUKPp+tHplz8Z1xrcdW6KLZIq/NO2VErhFol4xGj/8Z4ck8rnujY+ F/oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PWWoGd3X; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si313735pfn.361.2018.06.12.01.05.26; Tue, 12 Jun 2018 01:06:10 -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=pass header.i=@gmail.com header.s=20161025 header.b=PWWoGd3X; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933533AbeFLIDv (ORCPT + 99 others); Tue, 12 Jun 2018 04:03:51 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:40612 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932448AbeFLIDs (ORCPT ); Tue, 12 Jun 2018 04:03:48 -0400 Received: by mail-pl0-f68.google.com with SMTP id t12-v6so13894113plo.7 for ; Tue, 12 Jun 2018 01:03:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=e30WJON+WcienBTt3dkXZkI8oWzd8tFR4OMY8R/zNUM=; b=PWWoGd3XCkCnAF4dhrtA2YefN7f+oa2NzpgGwjm7e15mHm6No8FQFDxR78ENN7allY FD1vkSFvcoQNg3n4YZlshk5n9EkWh43EU6MDuz10O+DQaEjJWWl2Is3WDrkkEHJVYaka iWNoVSdw6Dib8A8kg/fQX/OsgrgxfcOBtPcZAflJtIYi15xuvKVUKx6oiybpBhURU7WE RLVszCYyFO9cT0QU4LqE5v2Zv9kle81M0uLdNPdD1d6cuSJhRyQAisIb3IUAmfxUbg4+ yUReEhNWf+E3bYTC440aUfn8QBLFFcjNlj1V5JOYMNtbyUtFo2oh0TuilULCwCxvz8rN 7aog== 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; bh=e30WJON+WcienBTt3dkXZkI8oWzd8tFR4OMY8R/zNUM=; b=c7NpPgCmubwsjMupmycP0rBaQVwE935qED9qdg3CEIiSDzepTF0P10XMPei8WSUS6u 6GRRA75SPxOK6O0Vs6RcNV1W6dWWkS4IEVxQ3VmtFT2gL69rlHer/pJvs9cSR1Hwn8Gw JIjOMB+PCdjYeWwBC5A7+PF46EmJ6jyOqsnqQtyA7ztFENE3/O7EI/OL0cAcjjkK46zI OvKBxvLyc0g3QZWHbe5PARNa5j6Bo0v5RLDASOtjyrzEY1gkwwRS2EmXgXyCOA5nGC8H MD2faUk1KLgStEBmJafqQYQYcvNowf1MuvtHq9Bel8fEywp96CyOQgikF+6J62YPFFiR 8V7Q== X-Gm-Message-State: APt69E0ih3VKqiDwMpI0RcCiw/IWmyBXT/Sq8K6QHv883c3yXSXNl27t i3gi8eAcLAsCRFa61syoxyfmKw== X-Received: by 2002:a17:902:14d:: with SMTP id 71-v6mr2865627plb.275.1528790628281; Tue, 12 Jun 2018 01:03:48 -0700 (PDT) Received: from localhost ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id x3-v6sm848065pfm.2.2018.06.12.01.03.47 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 12 Jun 2018 01:03:47 -0700 (PDT) From: Jing Xia X-Google-Original-From: Jing Xia To: agk@redhat.com, snitzer@redhat.com, dm-devel@redhat.com Cc: linux-kernel@vger.kernel.org Subject: [PATCH] dm bufio: Reduce dm_bufio_lock contention Date: Tue, 12 Jun 2018 16:03:28 +0800 Message-Id: <1528790608-19557-1-git-send-email-jing.xia@unisoc.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Performance test in android reports that the phone sometimes gets hanged and shows black screen for about several minutes.The sysdump shows: 1. kswapd and other tasks who enter the direct-reclaim path are waiting on the dm_bufio_lock; 2. the task who gets the dm_bufio_lock is stalled for IO completions, the relevant stack trace as : PID: 22920 TASK: ffffffc0120f1a00 CPU: 1 COMMAND: "kworker/u8:2" #0 [ffffffc0282af3d0] __switch_to at ffffff8008085e48 #1 [ffffffc0282af3f0] __schedule at ffffff8008850cc8 #2 [ffffffc0282af450] schedule at ffffff8008850f4c #3 [ffffffc0282af470] schedule_timeout at ffffff8008853a0c #4 [ffffffc0282af520] schedule_timeout_uninterruptible at ffffff8008853aa8 #5 [ffffffc0282af530] wait_iff_congested at ffffff8008181b40 #6 [ffffffc0282af5b0] shrink_inactive_list at ffffff8008177c80 #7 [ffffffc0282af680] shrink_lruvec at ffffff8008178510 #8 [ffffffc0282af790] mem_cgroup_shrink_node_zone at ffffff80081793bc #9 [ffffffc0282af840] mem_cgroup_soft_limit_reclaim at ffffff80081b6040 This patch aims to reduce the dm_bufio_lock contention when multiple tasks do shrink_slab() at the same time.It is acceptable that task will be allowed to reclaim from other shrinkers or reclaim from dm-bufio next time, rather than stalled for the dm_bufio_lock. Signed-off-by: Jing Xia Signed-off-by: Jing Xia --- drivers/md/dm-bufio.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index c546b56..402a028 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -1647,10 +1647,19 @@ static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan, static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { + unsigned long count; + unsigned long retain_target; + struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker); - unsigned long count = READ_ONCE(c->n_buffers[LIST_CLEAN]) + + + if (!dm_bufio_trylock(c)) + return 0; + + count = READ_ONCE(c->n_buffers[LIST_CLEAN]) + READ_ONCE(c->n_buffers[LIST_DIRTY]); - unsigned long retain_target = get_retain_buffers(c); + retain_target = get_retain_buffers(c); + + dm_bufio_unlock(c); return (count < retain_target) ? 0 : (count - retain_target); } -- 1.9.1