Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp9967ybj; Fri, 8 May 2020 05:25:00 -0700 (PDT) X-Google-Smtp-Source: APiQypK59McrIySMv8r52QJDy+rlDSkCEttoUJjCz4lO80IzIZiS9cFlVnmn8zLvB2RnuGjdWSfm X-Received: by 2002:a17:906:4f03:: with SMTP id t3mr1606961eju.254.1588940699896; Fri, 08 May 2020 05:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588940699; cv=none; d=google.com; s=arc-20160816; b=g6iLC/p1bINm4PiDS++asb1pcFOJEbMmaLBNQoiqXAKNYzLdsmqlHJEwiMYT272gpS qlTRngJWhHbjo8tzmfpulLW98J80Cm9JTcNtI2m1gnFUAox5HSd4Zd1PERJLDvKBLomc z+Vcs37TdY1pxLxIvb6Lkz0MNc2pgKsCLXKfCy+rlEb5+3wZzfRAUx9pJUBRua4IRgoP /4pvVdS1bj0DZ45cNFQo2FekrpXb6xJTSp8+8O1b8N3vHo3K59tRHRsasLly/a7H3iND /2aM+Vyo7zaI3XdDdU4n4NZ0HilXxKsWc5jFaSRGqyYjYnVk3pkLeGvhYRRaM1WP95HU Z1Jw== 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 :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=xT0Ek5AkKTFr9RUmYGBGy2702WCzdU/iKo4/jW8l2rI=; b=uZKq2/YxbCSZDTsBZkfyO8eWFgxRmCU3Lik7AOubcY6RaCxpcR8p3kk9vrY37E/n82 9OnExBFku/F8opVhI/JAwmd5vsgl1KVXIswqNwe0PnUkkz6g5geEud4jEd73Bmgi4yrw DDn8kl6fxxeQJiozLbrBGsPe8ATmYOXNOPMgMg4y9LS0BbF/VtLaL9QESLNJ/Z+qggoy D8ShhJzjN6pX8L6qbOtHLzsUJYkVXR27n+epHlrzog1/hxQFTN6TXdWHZe0Fde9YkKyf yhoAbwC/NGDcDoiP2HxHPuY6YYJqh4vt+EVJwYwvMoG0eqHYx/8eQ3b00/7r/hMo95t5 Ay8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=uTuF1hAn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n1si914949ejr.104.2020.05.08.05.24.36; Fri, 08 May 2020 05:24:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=uTuF1hAn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727030AbgEHMXQ (ORCPT + 99 others); Fri, 8 May 2020 08:23:16 -0400 Received: from forwardcorp1p.mail.yandex.net ([77.88.29.217]:34478 "EHLO forwardcorp1p.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726616AbgEHMXQ (ORCPT ); Fri, 8 May 2020 08:23:16 -0400 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1p.mail.yandex.net (Yandex) with ESMTP id 2AB602E1582; Fri, 8 May 2020 15:23:13 +0300 (MSK) Received: from myt5-70c90f7d6d7d.qloud-c.yandex.net (myt5-70c90f7d6d7d.qloud-c.yandex.net [2a02:6b8:c12:3e2c:0:640:70c9:f7d]) by mxbackcorp2j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id GRzGm9PEUB-NAXOq1Xu; Fri, 08 May 2020 15:23:13 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1588940593; bh=xT0Ek5AkKTFr9RUmYGBGy2702WCzdU/iKo4/jW8l2rI=; h=Message-ID:Date:To:From:Subject:Cc; b=uTuF1hAnXddRW2jNQcBypMq/F8E3wbskTSGE96DZ5cfc8XuqDEaCUTmqeEixb7w42 3eQg/bCp2nZvhZJ6gGDyFjPWXD9M6ixwGt8VcyWiQDyPD2jmlfrQFbAxg/TAuwhv3J RobvhWmmc/CuBPWyOVo5xxxVBrB2bd/c5eu8Xhhw= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:7008::1:4]) by myt5-70c90f7d6d7d.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id EvmtYS4l9K-NAWuaFi6; Fri, 08 May 2020 15:23:10 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Subject: [PATCH RFC 0/8] dcache: increase poison resistance From: Konstantin Khlebnikov To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro Cc: Waiman Long Date: Fri, 08 May 2020 15:23:09 +0300 Message-ID: <158893941613.200862.4094521350329937435.stgit@buzz> User-Agent: StGit/0.22-32-g6a05 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For most filesystems result of every negative lookup is cached, content of directories is usually cached too. Production of negative dentries isn't limited with disk speed. It's really easy to generate millions of them if system has enough memory. Getting this memory back ins't that easy because slab frees pages only when all related objects are gone. While dcache shrinker works in LRU order. Typical scenario is an idle system where some process periodically creates temporary files and removes them. After some time, memory will be filled with negative dentries for these random file names. Simple lookup of random names also generates negative dentries very fast. Constant flow of such negative denries drains all other inactive caches. Negative dentries are linked into siblings list along with normal positive dentries. Some operations walks dcache tree but looks only for positive dentries: most important is fsnotify/inotify. Hordes of negative dentries slow down these operations significantly. Time of dentry lookup is usually unaffected because hash table grows along with size of memory. Unless somebody especially crafts hash collisions. This patch set solves all of these problems: Move negative denries to the end of sliblings list, thus walkers could skip them at first sight (patches 3-6). Keep in dcache at most three unreferenced negative denties in row in each hash bucket (patches 7-8). --- Konstantin Khlebnikov (8): dcache: show count of hash buckets in sysctl fs.dentry-state selftests: add stress testing tool for dcache dcache: sweep cached negative dentries to the end of list of siblings fsnotify: stop walking child dentries if remaining tail is negative dcache: add action D_WALK_SKIP_SIBLINGS to d_walk() dcache: stop walking siblings if remaining dentries all negative dcache: push releasing dentry lock into sweep_negative dcache: prevent flooding with negative dentries fs/dcache.c | 144 +++++++++++- fs/libfs.c | 10 +- fs/notify/fsnotify.c | 6 +- include/linux/dcache.h | 6 + tools/testing/selftests/filesystems/Makefile | 1 + .../selftests/filesystems/dcache_stress.c | 210 ++++++++++++++++++ 6 files changed, 370 insertions(+), 7 deletions(-) create mode 100644 tools/testing/selftests/filesystems/dcache_stress.c -- Signature