29 #include <linux/module.h>
32 #include <linux/list.h>
34 #include <linux/slab.h>
36 #include <linux/types.h>
40 #include "../zcache.h"
46 #define RAMSTER_TESTING
49 #error "ramster needs sysfs to define cluster nodes to use"
57 static unsigned long ramster_interface_revision
__read_mostly =
59 static unsigned long ramster_pers_remotify_enable
__read_mostly;
60 static unsigned long ramster_eph_remotify_enable
__read_mostly;
62 #define MANUAL_NODES 8
67 static long ramster_flnodes;
69 static unsigned long ramster_flnodes_max;
70 static long ramster_foreign_eph_pages;
72 static unsigned long ramster_foreign_eph_pages_max;
73 static long ramster_foreign_pers_pages;
75 static unsigned long ramster_foreign_pers_pages_max;
76 static unsigned long ramster_eph_pages_remoted;
77 static unsigned long ramster_pers_pages_remoted;
78 static unsigned long ramster_eph_pages_remote_failed;
79 static unsigned long ramster_pers_pages_remote_failed;
80 static unsigned long ramster_remote_eph_pages_succ_get;
81 static unsigned long ramster_remote_pers_pages_succ_get;
82 static unsigned long ramster_remote_eph_pages_unsucc_get;
83 static unsigned long ramster_remote_pers_pages_unsucc_get;
84 static unsigned long ramster_pers_pages_remote_nomem;
85 static unsigned long ramster_remote_objects_flushed;
86 static unsigned long ramster_remote_object_flushes_failed;
87 static unsigned long ramster_remote_pages_flushed;
88 static unsigned long ramster_remote_page_flushes_failed;
91 #ifdef CONFIG_DEBUG_FS
93 #define zdfs debugfs_create_size_t
94 #define zdfs64 debugfs_create_u64
95 static int __init ramster_debugfs_init(
void)
101 zdfs(
"eph_pages_remoted",
S_IRUGO, root, &ramster_eph_pages_remoted);
102 zdfs(
"pers_pages_remoted",
S_IRUGO, root, &ramster_pers_pages_remoted);
103 zdfs(
"eph_pages_remote_failed",
S_IRUGO, root,
104 &ramster_eph_pages_remote_failed);
105 zdfs(
"pers_pages_remote_failed",
S_IRUGO, root,
106 &ramster_pers_pages_remote_failed);
107 zdfs(
"remote_eph_pages_succ_get",
S_IRUGO, root,
108 &ramster_remote_eph_pages_succ_get);
109 zdfs(
"remote_pers_pages_succ_get",
S_IRUGO, root,
110 &ramster_remote_pers_pages_succ_get);
111 zdfs(
"remote_eph_pages_unsucc_get",
S_IRUGO, root,
112 &ramster_remote_eph_pages_unsucc_get);
113 zdfs(
"remote_pers_pages_unsucc_get",
S_IRUGO, root,
114 &ramster_remote_pers_pages_unsucc_get);
115 zdfs(
"pers_pages_remote_nomem",
S_IRUGO, root,
116 &ramster_pers_pages_remote_nomem);
117 zdfs(
"remote_objects_flushed",
S_IRUGO, root,
118 &ramster_remote_objects_flushed);
119 zdfs(
"remote_pages_flushed",
S_IRUGO, root,
120 &ramster_remote_pages_flushed);
121 zdfs(
"remote_object_flushes_failed",
S_IRUGO, root,
122 &ramster_remote_object_flushes_failed);
123 zdfs(
"remote_page_flushes_failed",
S_IRUGO, root,
124 &ramster_remote_page_flushes_failed);
125 zdfs(
"foreign_eph_pages",
S_IRUGO, root,
126 &ramster_foreign_eph_pages);
127 zdfs(
"foreign_eph_pages_max",
S_IRUGO, root,
128 &ramster_foreign_eph_pages_max);
129 zdfs(
"foreign_pers_pages",
S_IRUGO, root,
130 &ramster_foreign_pers_pages);
131 zdfs(
"foreign_pers_pages_max",
S_IRUGO, root,
132 &ramster_foreign_pers_pages_max);
158 if (ramster_flnodes > ramster_flnodes_max)
159 ramster_flnodes_max = ramster_flnodes;
164 #define FLUSH_ENTIRE_OBJECT ((uint32_t)-1)
212 bool eph,
delete =
false;
213 void *pampd, *saved_hb;
222 pampd = tmem_localify_get_pampd(pool, oidp, index, &obj, &saved_hb);
225 #ifdef RAMSTER_TESTING
226 pr_err(
"UNTESTED pampd==NULL in ramster_localify\n");
229 ramster_remote_eph_pages_unsucc_get++;
231 ramster_remote_pers_pages_unsucc_get++;
234 }
else if (
unlikely(!pampd_is_remote(pampd))) {
236 #ifdef RAMSTER_TESTING
237 pr_err(
"UNTESTED dup while waiting in ramster_localify\n");
240 ramster_remote_eph_pages_unsucc_get++;
242 ramster_remote_pers_pages_unsucc_get++;
247 }
else if (size == 0) {
251 ramster_remote_eph_pages_unsucc_get++;
257 if (pampd_is_intransit(pampd)) {
264 pampd = pampd_mask_intransit_and_remote(pampd);
282 ramster_remote_eph_pages_succ_get++;
284 ramster_remote_pers_pages_succ_get++;
287 tmem_localify_finish(obj, index, pampd, saved_hb,
delete);
311 flnode = ramster_flnode_alloc(pool);
312 flnode->
xh.client_id = pampd_remote_node(obj->
extra);
314 flnode->
xh.oid = obj->
oid;
317 spin_lock(&ramster_rem_op_list_lock);
318 list_add(&flnode->
rem_op.list, &ramster_rem_op_list);
319 spin_unlock(&ramster_rem_op_list_lock);
333 int clen = pampd_remote_size(pampd),
c;
334 void *ret_pampd =
NULL;
338 BUG_ON(!pampd_is_remote(pampd));
340 if (use_frontswap_exclusive_gets)
343 if (pampd_is_intransit(pampd)) {
359 if (ret_pampd !=
NULL) {
365 ret_pampd = pampd_mark_intransit(ret_pampd);
369 ramster_pers_pages_remote_nomem++;
386 struct tmem_xhandle xh;
389 if (pampd_is_intransit(real_pampd))
395 pampd_remote_node(fake_pampd),
396 pampd_remote_size(fake_pampd),
397 pampd_remote_cksum(fake_pampd),
404 return pampd_is_remote(pampd);
411 if (new_pampd !=
NULL) {
413 obj->
extra = new_pampd;
416 else if (pampd_remote_node(new_pampd) !=
417 pampd_remote_node((
void *)(obj->
extra)))
428 void *local_pampd =
NULL;
432 BUG_ON(!pampd_is_remote(pampd));
441 }
else if (pampd_is_intransit(pampd)) {
443 local_pampd = pampd_mask_intransit_and_remote(pampd);
446 ramster_flnode_alloc(pool);
448 flnode->
xh.client_id = pampd_remote_node(pampd);
450 flnode->
xh.oid = *
oid;
453 spin_lock(&ramster_rem_op_list_lock);
454 list_add(&flnode->
rem_op.list, &ramster_rem_op_list);
455 spin_unlock(&ramster_rem_op_list_lock);
466 BUG_ON(count != 1 && count != -1);
470 &ramster_foreign_eph_pages_atomic);
471 if (c > ramster_foreign_eph_pages_max)
472 ramster_foreign_eph_pages_max =
c;
477 ramster_foreign_eph_pages =
c;
481 &ramster_foreign_pers_pages_atomic);
482 if (c > ramster_foreign_pers_pages_max)
483 ramster_foreign_pers_pages_max =
c;
486 &ramster_foreign_pers_pages_atomic);
489 ramster_foreign_pers_pages =
c;
500 ramster_remotify_process);
502 static void ramster_remotify_queue_delayed_work(
unsigned long delay)
505 &ramster_remotify_worker, delay))
506 pr_err(
"ramster_remotify: bad workqueue\n");
509 static void ramster_remote_flush_page(
struct flushlist_node *flnode)
511 struct tmem_xhandle *xh;
516 remotenode = flnode->
xh.client_id;
519 ramster_remote_pages_flushed++;
521 ramster_remote_page_flushes_failed++;
523 ramster_flnode_free(flnode,
NULL);
526 static void ramster_remote_flush_object(
struct flushlist_node *flnode)
528 struct tmem_xhandle *xh;
533 remotenode = flnode->
xh.client_id;
536 ramster_remote_objects_flushed++;
538 ramster_remote_object_flushes_failed++;
540 ramster_flnode_free(flnode,
NULL);
545 struct tmem_xhandle xh;
547 int remotenode,
ret, zbuds;
553 unsigned char *tmpmem[2];
555 unsigned int zsize[2];
566 for (i = 0; i < zbuds; i++) {
573 for (p = tmpmem[i], cksum = 0, j = 0; j <
size; j++)
589 ramster_eph_pages_remote_failed++;
591 ramster_pers_pages_remote_failed++;
598 ramster_eph_pages_remoted++;
600 ramster_pers_pages_remoted++;
609 pampd_make_remote(remotenode, size, cksum));
618 static void zcache_do_remotify_flushes(
void)
624 spin_lock(&ramster_rem_op_list_lock);
625 if (list_empty(&ramster_rem_op_list)) {
626 spin_unlock(&ramster_rem_op_list_lock);
631 list_del_init(&rem_op->
list);
632 spin_unlock(&ramster_rem_op_list_lock);
634 switch (rem_op->
op) {
651 static bool remotify_in_progress;
655 if (remotify_in_progress)
657 if (ramster_remote_target_nodenum == -1)
659 remotify_in_progress =
true;
660 if (use_cleancache && ramster_eph_remotify_enable) {
661 for (i = 0; i < 100; i++) {
662 zcache_do_remotify_flushes();
666 if (use_frontswap && ramster_pers_remotify_enable) {
667 for (i = 0; i < 100; i++) {
668 zcache_do_remotify_flushes();
672 remotify_in_progress =
false;
674 ramster_remotify_queue_delayed_work(
HZ);
679 unsigned long n = 60
UL;
680 ramster_remotify_workqueue =
682 ramster_remotify_queue_delayed_work(n *
HZ);
691 if (ramster_nodes_manual_up[i])
701 unsigned long node_num;
703 err = kstrtoul(buf, 10, &node_num);
705 pr_err(
"ramster: bad strtoul?\n");
708 if (node_num >= MANUAL_NODES) {
709 pr_err(
"ramster: bad node_num=%lu?\n", node_num);
712 if (ramster_nodes_manual_up[node_num]) {
713 pr_err(
"ramster: node %d already up, ignoring\n",
716 ramster_nodes_manual_up[node_num] =
true;
723 .attr = { .name =
"manual_node_up", .mode = 0644 },
724 .show = ramster_manual_node_up_show,
725 .store = ramster_manual_node_up_store,
728 static ssize_t ramster_remote_target_nodenum_show(
struct kobject *kobj,
731 if (ramster_remote_target_nodenum == -1
UL)
732 return sprintf(buf,
"unset\n");
734 return sprintf(buf,
"%d\n", ramster_remote_target_nodenum);
737 static ssize_t ramster_remote_target_nodenum_store(
struct kobject *kobj,
741 unsigned long node_num;
743 err = kstrtoul(buf, 10, &node_num);
745 pr_err(
"ramster: bad strtoul?\n");
747 }
else if (node_num == -1
UL) {
748 pr_err(
"ramster: disabling all remotification, "
749 "data may still reside on remote nodes however\n");
751 }
else if (node_num >= MANUAL_NODES) {
752 pr_err(
"ramster: bad node_num=%lu?\n", node_num);
754 }
else if (!ramster_nodes_manual_up[node_num]) {
755 pr_err(
"ramster: node %d not up, ignoring setting "
756 "of remotification target\n", (
int)node_num);
758 pr_info(
"ramster: node %d set as remotification target\n",
760 ramster_remote_target_nodenum = (
int)node_num;
762 pr_err(
"ramster: bad num to node node_num=%d?\n",
769 static struct kobj_attribute ramster_remote_target_nodenum_attr = {
770 .attr = { .name =
"remote_target_nodenum", .mode = 0644 },
771 .show = ramster_remote_target_nodenum_show,
772 .store = ramster_remote_target_nodenum_store,
775 #define RAMSTER_SYSFS_RO(_name) \
776 static ssize_t ramster_##_name##_show(struct kobject *kobj, \
777 struct kobj_attribute *attr, char *buf) \
779 return sprintf(buf, "%lu\n", ramster_##_name); \
781 static struct kobj_attribute ramster_##_name##_attr = { \
782 .attr = { .name = __stringify(_name), .mode = 0444 }, \
783 .show = ramster_##_name##_show, \
786 #define RAMSTER_SYSFS_RW(_name) \
787 static ssize_t ramster_##_name##_show(struct kobject *kobj, \
788 struct kobj_attribute *attr, char *buf) \
790 return sprintf(buf, "%lu\n", ramster_##_name); \
792 static ssize_t ramster_##_name##_store(struct kobject *kobj, \
793 struct kobj_attribute *attr, const char *buf, size_t count) \
796 unsigned long enable; \
797 err = kstrtoul(buf, 10, &enable); \
800 ramster_##_name = enable; \
803 static struct kobj_attribute ramster_##_name##_attr = { \
804 .attr = { .name = __stringify(_name), .mode = 0644 }, \
805 .show = ramster_##_name##_show, \
806 .store = ramster_##_name##_store, \
809 #define RAMSTER_SYSFS_RO_ATOMIC(_name) \
810 static ssize_t ramster_##_name##_show(struct kobject *kobj, \
811 struct kobj_attribute *attr, char *buf) \
813 return sprintf(buf, "%d\n", atomic_read(&ramster_##_name)); \
815 static struct kobj_attribute ramster_##_name##_attr = { \
816 .attr = { .name = __stringify(_name), .mode = 0444 }, \
817 .show = ramster_##_name##_show, \
825 static struct attribute *ramster_attrs[] = {
826 &ramster_interface_revision_attr.attr,
827 &ramster_remote_pers_pages_attr.attr,
828 &ramster_manual_node_up_attr.
attr,
829 &ramster_remote_target_nodenum_attr.
attr,
830 &ramster_pers_remotify_enable_attr.attr,
831 &ramster_eph_remotify_enable_attr.attr,
836 .attrs = ramster_attrs,
845 static unsigned int selfshrink_interval __read_mostly = 5;
849 static void selfshrink_process(
struct work_struct *work);
853 static bool use_frontswap_selfshrink
__initdata =
true;
862 static unsigned int frontswap_hysteresis __read_mostly = 20;
869 static unsigned int frontswap_inertia __read_mostly = 3;
872 static unsigned long frontswap_inertia_counter;
885 static void frontswap_selfshrink(
void)
887 static unsigned long cur_frontswap_pages;
888 static unsigned long last_frontswap_pages;
889 static unsigned long tgt_frontswap_pages;
891 last_frontswap_pages = cur_frontswap_pages;
893 if (!cur_frontswap_pages ||
894 (cur_frontswap_pages > last_frontswap_pages)) {
895 frontswap_inertia_counter = frontswap_inertia;
898 if (frontswap_inertia_counter && --frontswap_inertia_counter)
900 if (cur_frontswap_pages <= frontswap_hysteresis)
901 tgt_frontswap_pages = 0;
903 tgt_frontswap_pages = cur_frontswap_pages -
904 (cur_frontswap_pages / frontswap_hysteresis);
908 static int __init ramster_nofrontswap_selfshrink_setup(
char *
s)
910 use_frontswap_selfshrink =
false;
914 __setup(
"noselfshrink", ramster_nofrontswap_selfshrink_setup);
916 static void selfshrink_process(
struct work_struct *work)
918 if (frontswap_selfshrinking && frontswap_enabled) {
919 frontswap_selfshrink();
921 selfshrink_interval *
HZ);
930 per_cpu(ramster_remoteputmem1, cpu) =
p1;
931 per_cpu(ramster_remoteputmem2, cpu) = p2;
942 kp = &
per_cpu(ramster_preloads, cpu);
960 bool frontswap_exclusive_gets)
965 use_cleancache =
true;
967 use_frontswap =
true;
968 if (frontswap_exclusive_gets)
969 use_frontswap_exclusive_gets =
true;
970 ramster_debugfs_init();
973 pr_err(
"ramster: can't create sysfs for ramster\n");
975 INIT_LIST_HEAD(&ramster_rem_op_list);
978 frontswap_selfshrinking = use_frontswap_selfshrink;
979 if (frontswap_selfshrinking) {
980 pr_info(
"ramster: Initializing frontswap selfshrink driver.\n");
982 selfshrink_interval *
HZ);