GVKun编程网logo

Ubuntu 增加 swap 交换空间的步骤(ubuntu添加swap)

1

本文将分享Ubuntu增加swap交换空间的步骤的详细内容,并且还将对ubuntu添加swap进行详尽解释,此外,我们还将为大家带来关于24.SwapNodesinPairs、AddSwaponUbu

本文将分享Ubuntu 增加 swap 交换空间的步骤的详细内容,并且还将对ubuntu添加swap进行详尽解释,此外,我们还将为大家带来关于24. Swap Nodes in Pairs、Add Swap on Ubuntu、apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu、CAS(Compare and Swap)算法的相关知识,希望对你有所帮助。

本文目录一览:

Ubuntu 增加 swap 交换空间的步骤(ubuntu添加swap)

Ubuntu 增加 swap 交换空间的步骤(ubuntu添加swap)

1. 首先用命令 free 查看系统内 Swap 分区大小。 free -m

total used free shared buffers cached Mem: 2012 1960 51 0 748 950 -/+ buffers/cache: 260 1751 Swap: 255 0 255

可以看到 Swap 只有 255M,下面我们来扩大到 2G。

2. 创建一个 Swap 文件。 mkdir /swapfile cd /swapfile sudo dd if=/dev/zero of=swap bs=1024 count=2000000

出现下列提示,上面命令中的 count 即代表 swap 文件大小。

记录了 2000000+0 的读入 记录了 2000000+0 的写出 2048000000 字节 (2.0 GB) 已复制,63.3147 秒,32.3 MB / 秒

把生成的文件转换成 Swap 文件 sudo mkswap -f swap

Setting up swapspace version 1, size = 1999996 KiB no label, UUID=fee9ab21-9efb-47c9-80f4-57e48142dd69

3. 激活 Swap 文件。 sudo swapon swap

再次查看 free -m 的结果。

total used free shared buffers cached Mem: 2012 1971 41 0 572 1156 -/+ buffers/cache: 241 1770 Swap: 2209 0 2209

添加成功。

扩展: 如果需要卸载这个 swap 文件,可以进入建立的 swap 文件目录。执行下列命令。 sudo swapoff swap

如果需要一直保持这个 swap ,可以把它写入 /etc/fstab 文件。

/swapfile/swapfile none swap defaults 0 0

24. Swap Nodes in Pairs

24. Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head.

For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.

Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.

 

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* swapPairs(ListNode* head) {
        struct ListNode *tmphead,*ptr1,*ptr2;
        tmphead = new ListNode(0);
        ptr1 = new ListNode(0);
        ptr2 = new ListNode(0);
        tmphead->next = head;
        head = tmphead;

        while (head->next != NULL && head->next->next != NULL){
            ptr1 = head->next,ptr2 = head->next->next;
            //交换位置
            head->next = ptr2;     
            ptr1->next = ptr2->next;
            ptr2->next = ptr1;
            //更新待交换位置,由于ptr1更换到后位置,所以head=ptr1
            head = ptr1;
   
        }
        return tmphead->next;
    }
};

 

Add Swap on Ubuntu

Add Swap on Ubuntu

添加 4 个 G 的 swap

dd if=/dev/zero of=/swapfile bs=1024 count=4096k
mkswap /swapfile
swapon /swapfile

vi /etc/fstab

添加


/swapfile       none    swap    sw      0       0



chown root:root /swapfile 
chmod 0600 /swapfile


apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu

apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu

当运行apt-get update后出现如下错误时:
E: Some index files Failed to download,they have been ignored,or old ones used instead.

可以将目录下/var/lib/apt/lists/partial/所有的文件清掉,再次运行apt-get update即可!自带源在大陆不好。


出现以下错误:

ubuntu:Tempory failure resolving ''cn.archive.ubuntu.com ubuntu


修改dns:

1,重启生效:

sudovi/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)

在里面插入:
nameserver8.8.8.8
nameserver8.8.4.4

如果有多个DNS就一行一个

修改好保存,然后执行

sudoresolvconf-u

再看/etc/resolv.conf,最下面就多了2行:

cat/etc/resolv.conf
#Dynamicresolv.conf(5)fileforglibcresolver(3)generatedbyresolvconf(8)
#DONOTEDITTHISFILEBYHAND--YOURCHANGESWILLBEOVERWRITTEN
可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。


2,重启失效:

配置文件地址 /etc/resolv.conf

使用编辑器打开

改为如下内容:
search localdomain
nameserver 202.96.128.86 希望修改成的DNS
nameserver 202.96.128.166 备用DNS

重启网络:sudo /etc/init.d/networking restart。即可

CAS(Compare and Swap)算法

CAS(Compare and Swap)算法

CAS(Compare and Swap)算法:

1)原理:
	1)CAS有3个操作数,内存值V,预期值(旧值)A,要写入的新值B。
	2)当且仅当 预期值A=内存值V 时,将内存值V修改为新值B,否则什么都不做。
	3)CAS可以看作是一种乐观锁。

	
2)应用:用于管理对共享数据的并发访问。


3)CAS存在的问题:

	1)ABA问题:如果一个变量的值原来是A,然后变成了B,最后又变成了A,那么使用CAS进行检查时会发现它的值没有发生变化,但实际上却变化了。
		解决方法:使用版本号。
		
	2)循环时间长,开销大
	
	3)只能保证一个共享变量的原子操作
	
		说明:对一个共享变量进行操作时,可以使用循环CAS的方式来保证原子性,但是对多个共享变量进行操作时,循环CAS就无法保证操作的原子性了。
		
		解决方法:
			1>使用锁。
			2>把多个共享变量合并成一个共享变量来操作,即将多个共享变量封装到一个对象中,然后使用循环CAS对这个对象进行操作。
				eg:JDK提供了 java.util.concurrent.atomic.AtomicReference类 来保证引用对象之间的原子性。
	
	
4)java中原子操作的实现:
	1)使用锁
	2)循环CAS
	
	说明:除了偏向锁,JVM实现锁的方式都用了循环CAS,即:当一个线程想进入同步块的时候使用循环CAS的方式来获取锁,当它退出同步块的时候使用循环CAS来释放锁。

关于Ubuntu 增加 swap 交换空间的步骤ubuntu添加swap的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于24. Swap Nodes in Pairs、Add Swap on Ubuntu、apt-get update 失败 ubuntu:Tempory failure resolving 'cn.archive.ubuntu.com ubuntu、CAS(Compare and Swap)算法的相关信息,请在本站寻找。

本文标签: