alistair23-linux/net/core
Roman Gushchin b936ca643a bpf: rework memlock-based memory accounting for maps
In order to unify the existing memlock charging code with the
memcg-based memory accounting, which will be added later, let's
rework the current scheme.

Currently the following design is used:
  1) .alloc() callback optionally checks if the allocation will likely
     succeed using bpf_map_precharge_memlock()
  2) .alloc() performs actual allocations
  3) .alloc() callback calculates map cost and sets map.memory.pages
  4) map_create() calls bpf_map_init_memlock() which sets map.memory.user
     and performs actual charging; in case of failure the map is
     destroyed
  <map is in use>
  1) bpf_map_free_deferred() calls bpf_map_release_memlock(), which
     performs uncharge and releases the user
  2) .map_free() callback releases the memory

The scheme can be simplified and made more robust:
  1) .alloc() calculates map cost and calls bpf_map_charge_init()
  2) bpf_map_charge_init() sets map.memory.user and performs actual
    charge
  3) .alloc() performs actual allocations
  <map is in use>
  1) .map_free() callback releases the memory
  2) bpf_map_charge_finish() performs uncharge and releases the user

The new scheme also allows to reuse bpf_map_charge_init()/finish()
functions for memcg-based accounting. Because charges are performed
before actual allocations and uncharges after freeing the memory,
no bogus memory pressure can be created.

In cases when the map structure is not available (e.g. it's not
created yet, or is already destroyed), on-stack bpf_map_memory
structure is used. The charge can be transferred with the
bpf_map_charge_move() function.

Signed-off-by: Roman Gushchin <guro@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2019-05-31 16:52:56 -07:00
..
bpf_sk_storage.c bpf: rework memlock-based memory accounting for maps 2019-05-31 16:52:56 -07:00
datagram.c datagram: remove rendundant 'peeked' argument 2019-04-08 09:51:54 -07:00
datagram.h net/core: Allow the compiler to verify declaration and definition consistency 2019-03-27 13:49:44 -07:00
dev.c net: avoid weird emergency message 2019-05-16 14:25:58 -07:00
dev_addr_lists.c net: dev: Issue NETDEV_PRE_CHANGEADDR 2018-12-13 18:41:38 -08:00
dev_ioctl.c net/core: Document all dev_ioctl() arguments 2019-03-27 13:49:43 -07:00
devlink.c devlink: Change devlink health locking mechanism 2019-05-01 11:07:03 -04:00
drop_monitor.c treewide: Add SPDX license identifier for more missed files 2019-05-21 10:50:45 +02:00
dst.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
dst_cache.c net: core: dst_cache_set_ip6: Rename 'addr' parameter to 'saddr' for consistency 2018-03-05 12:52:45 -05:00
ethtool.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net 2019-04-05 14:14:19 -07:00
failover.c failover: allow name change on IFF_UP slave interfaces 2019-04-10 22:12:26 -07:00
fib_notifier.c net: Fix fib notifer to return errno 2018-03-29 14:10:30 -04:00
fib_rules.c fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied 2019-05-08 09:32:10 -07:00
filter.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2019-04-28 08:42:41 -04:00
flow_dissector.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
flow_offload.c flow_offload: support CVLAN match 2019-05-16 12:02:42 -07:00
gen_estimator.c net: core: protect rate estimator statistics pointer with lock 2018-08-11 12:37:10 -07:00
gen_stats.c Revert: "net: sched: put back q.qlen into a single location" 2019-04-10 12:20:46 -07:00
gro_cells.c gro_cells: make sure device is up in gro_cells_receive() 2019-03-10 11:07:14 -07:00
hwbm.c net: hwbm: Fix unbalanced spinlock in error case 2016-05-25 12:35:09 -07:00
link_watch.c net: linkwatch: add check for netdevice being present to linkwatch_do_dev 2018-09-19 21:06:46 -07:00
lwt_bpf.c netlink: make validation more configurable for future strictness 2019-04-27 17:07:21 -04:00
lwtunnel.c netlink: make nla_nest_start() add NLA_F_NESTED flag 2019-04-27 17:03:44 -04:00
Makefile bpf: Introduce bpf sk local storage 2019-04-27 09:07:04 -07:00
neighbour.c neighbor: Add tracepoint to __neigh_create 2019-05-22 17:50:24 -07:00
net-procfs.c treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively 2019-04-09 14:19:06 +02:00
net-sysfs.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-05-07 22:03:58 -07:00
net-sysfs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
net-traces.c trace: events: add a few neigh tracepoints 2019-02-17 10:33:39 -08:00
net_namespace.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
netclassid_cgroup.c cgroup, netclassid: add a preemption point to write_classid 2018-10-23 12:58:17 -07:00
netevent.c netevent: remove automatic variable in register_netevent_notifier() 2015-05-31 00:03:21 -07:00
netpoll.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
netprio_cgroup.c cgroup: net: remove left over MODULE_LICENSE tag 2019-04-22 21:50:54 -07:00
page_pool.c page_pool: use DMA_ATTR_SKIP_CPU_SYNC for DMA mappings 2019-02-13 22:00:16 -08:00
pktgen.c xfrm: remove output indirection from xfrm_mode 2019-04-08 09:14:28 +02:00
ptp_classifier.c net/core: work around section mismatch warning for ptp_classifier 2019-04-16 20:46:17 -07:00
request_sock.c ipv4: Namespaceify tcp_max_syn_backlog knob 2016-12-29 11:38:31 -05:00
rtnetlink.c rtnetlink: always put IFLA_LINK for links with a link-netnsid 2019-05-14 15:40:01 -07:00
scm.c socket: Add SO_TIMESTAMPING_NEW 2019-02-03 11:17:31 -08:00
secure_seq.c treewide: Add SPDX license identifier for missed files 2019-05-21 10:50:45 +02:00
skbuff.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2019-04-22 21:35:55 -07:00
skmsg.c bpf: sockmap fix msg->sg.size account on ingress skb 2019-05-14 01:31:43 +02:00
sock.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2019-04-28 08:42:41 -04:00
sock_diag.c net: sock_diag: Fix spectre v1 gadget in __sock_diag_cmd() 2018-08-14 10:01:24 -07:00
sock_map.c bpf: rework memlock-based memory accounting for maps 2019-05-31 16:52:56 -07:00
sock_reuseport.c net/core: Document reuseport_add_sock() bind_inany argument 2019-03-27 13:49:43 -07:00
stream.c tcp: reduce POLLOUT events caused by TCP_NOTSENT_LOWAT 2018-12-04 21:21:18 -08:00
sysctl_net_core.c net: convert rps_needed and rfs_needed to new static branch api 2019-03-23 21:57:38 -04:00
timestamping.c net: skb_defer_rx_timestamp should check for phydev before setting up classify 2015-07-09 14:17:15 -07:00
tso.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
utils.c net: Remove some unneeded semicolon 2018-08-04 13:05:39 -07:00
xdp.c xdp: remove redundant variable 'headroom' 2018-09-01 01:35:53 +02:00